[英]If condition doesn't run but else condition works
我正在使用Firebase制作登录页面。 在身份验证的错误处理部分中,当error != null
起作用但error == null
不会进入控制台时。
firebase.auth().signInWithEmailAndPassword(userEmail, userPassword).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
if(errorMessage == null){
console.log('loginsucess');
}else{
console.log('error was present');
//window.alert(errorMessage);
}
});
存在错误将在控制台中打印,但是即使没有错误, loginsucess也不会。
仅当引发错误时, catch
才会运行。 您的if块永远不会运行,因为catch函数中总是存在错误
尝试
firebase.auth().signInWithEmailAndPassword(userEmail, userPassword)
.then(() => console.log('loginsuccess'))
.catch((error) => console.log('something is wrong...'))
你可以试试看
signInWithEmailAndPassword = (event) => {
event.preventDefault();
firebase
.auth()
.signInWithEmailAndPassword(email, password).then(() => {
console.log("login sucessfully");
}).catch((error) => {
console.log('hey error: ', error);
})
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.