Angularjs 刷新页面时,Firebase authData将变为空
我已使用firebase google身份验证对该用户进行了身份验证。问题是当我刷新页面时,会话过期,Angularjs 刷新页面时,Firebase authData将变为空,angularjs,firebasesimplelogin,firebase-authentication,Angularjs,Firebasesimplelogin,Firebase Authentication,我已使用firebase google身份验证对该用户进行了身份验证。问题是当我刷新页面时,会话过期,authData变为null。如何在刷新页面后,使我的authData与身份验证时获得的数据保持一致?您需要: //注册每次身份验证状态更改时要触发的回调 var ref=新的火基(“https://.firebaseio.com"); ref.onAuth(函数authDataCallback(authData){ if(authData){ console.log(“用户”+authData
authData
变为null
。如何在刷新页面后,使我的authData
与身份验证时获得的数据保持一致?您需要:
//注册每次身份验证状态更改时要触发的回调
var ref=新的火基(“https://.firebaseio.com");
ref.onAuth(函数authDataCallback(authData){
if(authData){
console.log(“用户”+authData.uid+”使用“+authData.provider”登录);
}否则{
console.log(“用户已注销”);
}
});
请注意,您没有使用AngularFire身份验证包装器。虽然您的方法将对用户进行身份验证,但您必须亲自通知Angular更新的作用域(请参见$timeout()
)。如果你不想自己做这件事,请看AngularFire的auth包装,尤其是
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();
}
});
};
// 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");
}
});