首页 > 解决方案 > JS/Jquery 和 firebase 登录页面问题

问题描述

我正在尝试建立一个登录页面。用户正确登录后,我想退出 index.html 页面并重定向到我的portfolio.html 页面。

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");

  }
});

上面的代码确实会切换页面,但会在循环中不断地重新加载页面。我很卡朋友:(。

感谢您的时间。

标签: javascriptjqueryfirebaseloopsfirebase-authentication

解决方案


是不是,您被重定向到了portfolio.html,执行了授权代码,用户对象已经存在,所以它再次将您重定向到portfolio。尝试添加

if(window.location.indexOf("portfolio.html") === -1){
//redirection here
}

推荐阅读