【问题标题】:When I refresh my page Firebase authData becomes null当我刷新页面时,Firebase authData 变为 null
【发布时间】:2015-11-04 07:22:45
【问题描述】:
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 身份验证对用户进行了身份验证。问题是当我刷新页面时,我的会话过期并且authData 变为null。我该怎么做才能在刷新页面后我的authData 保留在身份验证时获得的数据?

【问题讨论】:

    标签: angularjs firebasesimplelogin firebase-authentication


    【解决方案1】:

    你会想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 的身份验证包装器,特别是 $onAuth()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-27
      • 2020-02-15
      • 1970-01-01
      • 1970-01-01
      • 2016-11-21
      • 1970-01-01
      • 2019-07-04
      • 1970-01-01
      相关资源
      最近更新 更多