我正在尝试使用Firebase进行持久的Google身份验证。我可以成功登录,但如果我重新加载页面,会话将不会持续。
下面是我的代码:
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL)
.then(function()
{
let provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider)
.then(function (result)
{
//Save auth data
});
})
.catch(function(error)
{
console.error(error);
});
这基本上就是文档中所写的内容,应该非常简单。我真的不知道我错过了什么。
此外,我不知道当会话是永久会话时会发生什么,它只会静默地进行身份验证,还是会打开弹出窗口,进行身份验证,然后自动关闭弹出窗口?
谢谢!
发布于 2019-05-23 08:03:40
登录状态会自动保存到浏览器的本地存储中,并在页面/应用程序重新加载时恢复。要检测身份验证状态的更改,请使用here所示的onAuthStateChanged
侦听器
用户firebase.auth().onAuthStateChanged(function(user) { if (
){ //用户已登录。}否则{ //没有用户登录。} });
此侦听器将在用户主动登录时(即,当对signInWithPopup
的调用完成时)以及在重新加载应用程序/页面后用户登录状态恢复时触发。
https://stackoverflow.com/questions/56266211
复制相似问题