我的登录功能运行良好,但注销后将我重定向到我的登录登录页面。登录js中的AuthState不变,是错误还是我的代码有错误。
Login.js
function loginBtn(){
var userEmail = document.getElementById("email_field").value;
var userPass = document.getElementById("password_field").value;
firebase.auth().signInWithEmailAndPassword(userEmail,userPass).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
console.log(error.Message);
window.alert("Error : " + errorMessage);
});
}
firebase.auth().onAuthStateChanged(user => {
if(user) {
window.location = '/home';
}
});
function recaptchaCallback() {
$('#submitBtn').removeAttr('disabled');
};
Auth.js
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
} else {
// No user is signed in.
firebase.auth().signOut();
alert('NOT LOGGED IN');
window.location='/';
}
});
function logout(){
firebase.auth().signOut();
alert('SIGNED OUT');
window.location='/';
}
答案 0 :(得分:0)
由于侦听器加载速度太慢,我将OnAuthStateChanged放置到文档中来解决了该问题。
$(document).ready(function(){
firebase.auth().onAuthStateChanged(user => {
if(user) {
window.location = '/home';
}
});
});