javascript - 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");
}
});
上面的代码确实会切换页面,但会在循环中不断地重新加载页面。我很卡朋友:(。
感谢您的时间。
解决方案
是不是,您被重定向到了portfolio.html,执行了授权代码,用户对象已经存在,所以它再次将您重定向到portfolio。尝试添加
if(window.location.indexOf("portfolio.html") === -1){
//redirection here
}
推荐阅读
- python - 计算python中AB测试中多种变化的显着性
- android - KitKat 4.2 和 Nougat 7.1.1 之间的文件系统访问有何不同?
- python - CYK算法实现
- angular - 模型的Angular-Web api post方法为null
- mysql - Spring Boot:编码密码看起来不像 BCrypt
- sql - 订单连接字段
- javascript - 未捕获的 TypeError:renderIncomes.overIncome 不是 HTMLInputElement 中的函数。
- php - 基于事件的断点
- c++ - 如何允许大写和小写用户输入?
- node.js - 如何从 MongoDB 中快速检索大数组