ios - 如何检查用户是否在 firebase swift 应用程序中正确登录?
问题描述
我有问题,即使我输入了错误的密码,我的应用程序也会向我显示有关成功登录的信息,但实际上我没有。如何使其正常工作?
Auth.auth().fetchSignInMethods(forEmail: userEmail, completion: {
(providers, error) in
if error != nil {
self.displayAlertMessage(alertTitle: "Unhandled error", alertMessage: "Undefined error #SignUpViewController_0001");
return;
} else if providers == nil {
self.displayAlertMessage(alertTitle: "Error", alertMessage: "This account is not exist.");
return;
}
})
// Login
Auth.auth().signIn(withEmail: userEmail, password: userPassword) { [weak self] authResult, error in
guard self != nil else {
self?.displayAlertMessage(alertTitle: "Alert", alertMessage: "Wrong password.");
return }
}
self.displayAlertMessage(alertTitle: "Success", alertMessage: "You are successfuly sign in.", dismiss: true);
// Return to initial view
解决方案
Auth.auth().signIn()
是异步的并立即返回。稍后将使用登录结果调用您传递的回调。您的代码所做的是self.displayAlertMessage(alertTitle: "Success",...)
在登录完成之前立即调用。您应该只期望回调内的登录结果,而不是调用后的下一行代码signIn()
。
推荐阅读
- delphi - 如何让控制台应用程序的主线程成为 MTA?
- html - 如何删除 MUI 表中单元格之间的线条
- asp.net - 我有一个父视图,并且在加载父视图时在带有表格的局部视图中,只要表格没有数据,我就想隐藏局部视图
- composer-php - Composer 总是将相同的包重写到缓存中
- javascript - 如何使用 jquery 或 javascript 以 HTML 形式显示本地存储数据?
- c# - 如何在 FluentValidation 中返回整个模型的键
- ios - 从容器播放视频
- javascript - 我们可以从文本中间搜索正则表达式吗?
- regex - 正则表达式确定文件名中的 YYYYMMDD 模式
- angular - Angular Build 失败