Tako Tako - 1 year ago 191
AngularJS Question

Firebase 3. authentication doesn't persist

I'm working with firebase in a angularJS app, using the email and password authentication.
I just update my app from Firebase 2.x to 3.x and AngularFire from 1.x to 2.x.

I followed these 2 docs to do the migration :

But now, each time I refresh my page, I need to re-authenticate, like there is no persistent session.

I've checked the localStorage key
I have an
in the past (actually it's set with the timestamp of my login).

To check if the user is loggedin I use :


Here is a working example of my problem (login: toto@mail.fr / password: toto123)

Does anybody know why this behavior ?

Answer Source

I am gonna guess that you are checking the currentUser directly without waiting for the initial auth state to resolve. You need to add an observer:

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // User is signed in.
  } else {
    // No user is signed in.


Also, auth state is stored in web storage so make sure you have that enabled. (state will not persist in safari private mode browsing for example).