加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 18:08:39 所属栏目:安全 来源:网络整理
导读: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 { c
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保留了它在验证时获得的数据?

解决方法

你想要 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()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读