【发布时间】:2018-11-19 08:48:46
【问题描述】:
我们有一个最近更新到 Firebase 5、Swift 4 的现有项目,但我们的身份验证错误处理似乎无法正常工作。
我在 SO 上找到了几个答案,但这些似乎不再适用:
假设一个用户正在登录,他们输入了一个有效的电子邮件和无效的密码,它们被传递给下面的代码进行身份验证
Auth.auth().signIn(withEmail: user, password: pw, completion: { (auth, error) in
if error != nil {
let errDesc = error?.localizedDescription
print(errDesc!) //prints 'The password is invalid'
let err = error!
let errCode = AuthErrorCode(rawValue: err._code)
switch errCode {
case .wrongPassword: //Enum case 'wrongPassword' not found in type 'AuthErrorCode?'
print("wrong password")
default:
print("unknown error")
}
} else {
print("succesfully authd")
}
})
以前,我们可以使用 FIRAuthErrorCode 来比较可能的错误,例如 FIRAuthErrorCodeInvalidEmail、FIRAuthErrorCodeWrongPassword 等,但由于这一行的错误,上面发布的代码将无法编译
case .wrongPassword: Enum case 'wrongPassword' not found in type 'AuthErrorCode?'
奇怪的是,如果我通过键入来使用自动填充
case AuthErrorCode.wr
.wrongPassword is a selectable option and when seleted the compiler shows
Enum case 'wrongPassword' is not a member of type 'AuthErrorCode?'
即使它是一个可选择的选项。
【问题讨论】:
标签: swift firebase firebase-authentication