Javascript JS/Jquery和firebase登录页面问题
我正在尝试建立一个登录页面。用户正确登录后,我想退出index.html页面并重定向到myportfolio.html页面Javascript JS/Jquery和firebase登录页面问题,javascript,jquery,firebase,loops,firebase-authentication,Javascript,Jquery,Firebase,Loops,Firebase Authentication,我正在尝试建立一个登录页面。用户正确登录后,我想退出index.html页面并重定向到myportfolio.html页面 firebase.auth().onAuthStateChanged(user => { if(user) { window.location = 'portfolio.html'; } else { // No user is signed in. // window.location = 'index.html'; console.log("Not l
firebase.auth().onAuthStateChanged(user => {
if(user) {
window.location = 'portfolio.html';
} else {
// No user is signed in.
// window.location = 'index.html';
console.log("Not logged in");
}
});
上面的代码确实切换了页面,但是在循环中不断地反复加载页面。我是一个非常固执的朋友
谢谢您的时间。您被重定向到portfolio.html,身份验证代码被执行,用户对象已经存在,因此它再次将您重定向到portfolio。请尝试添加
if(window.location.indexOf("portfolio.html") === -1){
//redirection here
}
我想问题是,这段代码也在您的portfolio.html中执行。因此,当加载页面时,firebase会检查是否有用户从web存储登录,在您的情况下,该用户以前已登录。因此,将再次触发侦听器并重新加载页面。原因可能是当页面重新加载时,您没有再次登录。是否启用身份验证状态持久性?请查看此处