javascript - 如果用户输入错误的密码,如何停止导航?
问题描述
如果用户输入错误的密码,如何停止导航。发现错误后,我的应用程序仍在重定向。我已经尝试过这个简单的 If 条件,但它似乎不起作用。
login = (email,password)=>{
try{
firebase.auth().signInWithEmailAndPassword(email,password)
.then(function(user){
console.log(user)
});
}
catch(error){
console.log(error.toString())
if(error===true) {
return; //stop the execution of function
}
}
this.props.navigation.replace('Home')
}
解决方案
您的版本是正确的,但error
不是布尔值,因此您无法检查它是否正确,=== true
但您可以通过简单地检查它是否存在if (error)
并且它应该可以工作
login = (email,password)=>{
try {
firebase.auth().signInWithEmailAndPassword(email,password)
.then(function(user){
console.log(user)
});
} catch(error) {
console.log(error.toString())
if(error) {
return; //stop the execution of function
}
}
this.props.navigation.replace('Home')
}
推荐阅读
- visual-studio - 在即时窗口 Visual Studio 中调用异步方法
- google-places-api - Google 地方信息配额问题
- vba - Access/VBA Sub 每隔一段时间工作一次,其他时间抛出 1004 错误
- c++ - C ++模板函数不能将'std:string'转换为'double'作为回报
- reactjs - 更新 twilio flex 网络聊天配置
- git - 在 Git 中获取当前签出的完整参考名称
- angular - Angular:没有重载匹配此调用错误
- ssis - BIML 错误:无法解析对属性“属性”中的 OdbcSource12.SQLCommand 的引用。'' 是无效的
- html - 是否可以为一张特定图像使用物理像素而不是逻辑像素?
- sas - 将 SAS 代码转换为另一种语言,以变成独立的可分发 exe