[英]When I refresh my page Firebase 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();
}
});
};
我已使用firebase google身份驗證對用戶進行了身份驗證。 問題是當我刷新頁面時,我的會話到期並且authData
變為null
。 我可以做什么,以便在刷新頁面后,我的authData
保留了它在驗證時獲得的數據?
您需要監控身份驗證狀態 :
// 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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.