When I refresh my Firebase page, authData becomes null

var user = null; this.showLoginDialogGoogle = function(){ var ref = new Firebase("https://googlelogin1.firebaseio.com"); ref.authWithOAuthPopup("google", function(error, authData) { if (error) { console.log("Login Failed!", error); } else { console.log("Authenticated successfully with payload:", authData); user = authData; This.goToPage('/profile'); $rootScope.flag=true; $rootScope.$digest(); } }); }; 

I authenticated the user using Google Firebase authentication. The problem is that when I refresh my page, my session ends and authData becomes null . What can I do to ensure that after updating the page my authData stays with the data received during authentication?

+5
source share
1 answer

Do you want to track authentication status :

 // Register the callback to be fired every time auth state changes var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com"); ref.onAuth(function authDataCallback(authData) { if (authData) { console.log("User " + authData.uid + " is logged in with " + authData.provider); } else { console.log("User is logged out"); } }); 

Please note that you are not using AngularFire authentication wrappers. Although your approach will authenticate the user, you will need to notify Angular of the updated scope (see $timeout() ). If you prefer not to do this yourself, look at the AutumnFire wrappers, in particular $onAuth()

+1
source

All Articles