当我刷新页面时,Firebase authData变为null

Ham*_*riq 6 angularjs firebasesimplelogin firebase-authentication

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();
            }
        });
    };
Run Code Online (Sandbox Code Playgroud)

我已使用firebase google身份验证对用户进行了身份验证.问题是,当我刷新页面时,我的会话过期并authData变为null.我可以做什么,以便刷新页面后我的authData遗骸与认证时获得的数据一致?

Fra*_*len 1

您需要监视身份验证状态

// 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");
  }
});
Run Code Online (Sandbox Code Playgroud)

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