【发布时间】:2020-07-13 03:56:34
【问题描述】:
我在使用过去可以正常工作的两个 html 页面时遇到了一个小问题。
首先,我有一个包含这种代码的登录页面(login.html):
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
window.open("main.html",'_self');
} else {
// No user is signed in.
prompt for login ....
......
}
});
其次,我也有这个页面(main.html)包含这种代码:
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
do serious work ....
......
} else {
// Let us double check:
let theUser = firebase.auth().currentUser;
if (!theUser) {
// No user is signed in.
window.open("login.html",'_self');
}
// We need some patience :)
......
}
});
一旦用户登录,事情应该转到 main.html;这就是它过去的工作方式。但是现在,不知什么原因;当我登录时,即使我提供了我的凭据,流程也会转到 main.html(应该如此),但会立即反弹回 login.html。
我已经能够检查该块(在 main.html 中):
firebase.auth().onAuthStateChanged(function(user) {...}
没有检测到我已登录。这是为什么呢?
附: 我已验证我的域已添加到 Firebase 控制台的授权域列表中。
【问题讨论】:
标签: javascript firebase firebase-authentication