Firebase becomes null after page refresh

998 views
Skip to first unread message

מעיין ז

unread,
Apr 15, 2017, 3:23:39 PM4/15/17
to Firebase Google Group
Hi

I am building an Angular 2 app and using firebase as my authentication service. My app currently consists two pages, a login page and a settings page. 
When the user successfully login I AM getting back the details on the authenticated user on all pages, However, when the user is in the settings page and refreshes the page the firebase instance becomes null and the only way to initialize it is by re authenticating.

To over comes this I tried to use the localstorage however I dont think it is wise to keep the user credentials there so another approach I thought of using is by getting a token upon login however when I am using the "createcustomToken" method I get an error " WEBPACK_IMPORTED_MODULE_4_firebase_app__.auth(...).createCustomToken is not a function"

so my questions is how can I overcome this and make sure that the user is indeed authenticated.

Thanks, 

Bassam

unread,
Apr 15, 2017, 7:03:30 PM4/15/17
to Firebase Google Group
Can you provide more details? What is different about the settings page compared to your other pages? Code snippets would be very helpful.
Also, are you testing in the latest version 3.7.8? Can you try to isolate what version this issue started happening? It would help us figure out the cause for this issue.

Thank you.
Bassam

Doug Thompson

unread,
Apr 17, 2017, 7:57:36 AM4/17/17
to Firebase Google Group
Not sure because there's not a lot of detail here, but we had a weird edge case issue using AngularFire and Angular 1.0.

You can see the thread here:

Basically, we had code which was supposed to be activated based on an auth change. But we were getting different results in different browsers from this code:

vm.auth.$onAuthStateChanged(function(firebaseUser) {
   
if (firebaseUser) {
      vm
.validUser = firebaseUser;
      
//console.log("Signed in as:", firebaseUser.uid);
  
} else {
     
// When refreshing browser in Firefox, Safari or mobile browsers this gets triggered. Does not get triggered on Chrome desktop.
     console
.log("Signed out");   
     $location
.path('/');  // Redirects to home
  
}
});

Not sure if this is at all related. 

We didn't have a response from the Firebase team on whether this was expected behavior.

D
Reply all
Reply to author
Forward
0 new messages