
我正在尝试检查用户是否已使用firebase.auth().onAuthStateChanged()登录。当我运行代码时,应用程序不加载/呈现任何页面。
发布于 2020-04-23 21:20:06
在应用程序启动时,firebase状态不会更改。
尝试使用:
firebase.auth().currentUser对用户进行身份验证。
发布于 2020-04-23 21:36:02
您需要检查用户,如官方文档中的示例所示:
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
} else {
// No user is signed in.
}
});侦听器本身用于检测更改;您可以根据user对象从内部定义登录/注销行为。
当没有用户时,user将为空,因此将发生您的注销情况;
当有用户时,对象将是真实的,触发签入情况,上面有许多属性,如user.email等--有关更多信息,请参阅文档。
https://firebase.google.com/docs/auth/web/manage-users#get_the_currently_signed-in_user
发布于 2020-04-24 15:57:47
为您解决所有问题
let app;
firebase.auth().onAuthStateChanged(user => {
console.log("user", user);
if (!app) {
app = new Vue({
router,
store,
render: h => h(App)
}).$mount("#app");
}
});https://stackoverflow.com/questions/61387941
复制相似问题