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();
            }
        });
    };

我已使用Firebase Google身份验证对用户进行身份验证。问题是,当我刷新页面时,我的 session 到期并且authData变成null。我应该怎么做,以致刷新页面后,我的authData仍与认证时获得的数据保持在一起?

最佳答案

您将要monitor authentication state:

// 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");
  }
});

请注意,您未使用AngularFire身份验证包装器。尽管您的方法将对用户进行身份验证,但您必须自己将更新的范围通知Angular(请参阅$timeout())。如果您不想自己这样做,请查看AngularFire的auth包装器,特别是 $onAuth()

关于angularjs - 当我刷新页面时,Firebase authData变为null,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31952423/

10-12 03:39