【发布时间】:2019-11-15 19:27:07
【问题描述】:
在我的网站中,默认页面是 index.html。如果用户未连接,则将他重定向到登录页面。当用户登录后,程序应该将他重定向回 index.html 并显示页面。但是,当我登录(并且凭据正确)时,它会再次将我重定向到登录页面。
这是索引页面的代码:
var user = firebase.auth().currentUser;
if (!user){
window.location = 'https://anastasispap.me/auth/login.html';
}
登录页面代码:
const loginForm = document.querySelector('#login-form');
loginForm.addEventListener('submit', (e) => {
e.preventDefault();
const email = loginForm['login-email'].value;
const password = loginForm['login-password'].value;
console.log(email, password)
auth.signInWithEmailAndPassword(email, password).then(cred => {
console.log(cred)
loginForm.reset()
window.location.assign("https://anastasispap.me/index.html")
})
})
感谢您的宝贵时间:)
【问题讨论】:
标签: javascript html firebase firebase-authentication