【发布时间】:2021-04-28 09:51:59
【问题描述】:
我正在使用 JavaScript 中的 Firebase。
我使用onAuthStateChanged函数检查用户是否登录,然后重定向到相应的html页面。
auth.onAuthStateChanged((user) => {
if(user) {
// Logged in
console.log("logged in!");
window.location.href = "dashboard.html";
fetchFromDB();
} else {
console.log("Logged out!");
//window.location.href = "index.html";
}
});
但是,它会不断刷新页面,就像处于无限循环中一样。我不确定在这里做什么。
非常感谢您的帮助:)
【问题讨论】:
-
重定向导致页面刷新,使用户重新登录,触发 onAuthStateChanged...导致重定向...n
标签: javascript firebase firebase-authentication