我实施FireAuth error
和firebase email
的{{1}}代码,除了2个案例外,它们都有效。当password signup
字段为空时,会调用email address
。当我输入一些case .errorCodeInvalidEmail
时,会调用默认情况。对于letters (no valid email address)
,反过来说。当我输入一个字符时,password field
"叫做。当我将该字段留空时,我将转到默认情况。
这是我的代码:
ErrorCodeWeakPassword
我不知道哪些错误代码会处理错误的电子邮件格式或文档中的空密码字段。我可以尝试自己处理它们,但我认为@IBAction func SignInButtonPressed(_ sender: LogInVcButton) {
if let email = emailField.text, let password = pwdField.text {
FIRAuth.auth()?.signIn(withEmail: email, password: password, completion: { (user, error) in
if error == nil {
print("Email User Authenticated with Firebase")
} else {
FIRAuth.auth()?.createUser(withEmail: email, password: password, completion: { (user, error) in
if error != nil {
if let errCode = FIRAuthErrorCode(rawValue: (error?._code)!) {
switch errCode {
case .errorCodeEmailAlreadyInUse: self.errorMessage(message: "Email address is already in use")
case .errorCodeInvalidEmail: self.errorMessage(message: "Email address is invalid")
case .errorCodeWrongPassword: self.errorMessage(message: "Wrong password")
case .errorCodeWeakPassword: self.errorMessage(message: "Password needs to be minimum 6 characters")
// TODO: A case for if the password field is blank
default: print("default")
}
} else {
print("Successfully Authenticated with Firebase")
}
}
})
}
})
}
}
会涵盖这些情况? https://firebase.google.com/docs/auth/ios/errors
任何人都可以帮助我吗?
编辑:在深入挖掘后,我设法打印出错误的firebase描述。
可选(错误域= FIRAuthErrorDomain代码= 17008"电子邮件地址格式错误。" UserInfo = {NSLocalizedDescription =电子邮件地址格式错误。,error_name = ERROR_INVALID_EMAIL})
大小写.errorCodeInvalidEmail被调用。这没关系
可选(错误域= FIRAuthErrorDomain代码= 17999"发生内部错误,打印并检查错误详细信息以获取更多信息。" UserInfo = {NSUnderlyingError = 0x6080000565c0 Domain = FIRAuthInternalErrorDomain Code = 3&# 34;(null)" UserInfo = {FIRAuthErrorUserInfoDeserializedResponseKey = { 代码= 400; 错误=( { domain = global; message =" MISSING_PASSWORD&#34 ;; reason =无效; } ); message =" MISSING_PASSWORD&#34 ;; },} error_name = ERROR_INTERNAL_ERROR,NSLocalizedDescription =发生内部错误,打印并检查错误详细信息以获取更多信息。})
NOK .errorCodeInternalError:它说缺少密码,但应检查电子邮件地址
可选(错误域= FIRAuthErrorDomain代码= 17008"电子邮件地址格式错误。" UserInfo = {NSLocalizedDescription =电子邮件地址格式错误。,error_name = ERROR_INVALID_EMAIL})
这似乎没问题
可选(错误域= FIRAuthErrorDomain代码= 17999"发生内部错误,打印并检查错误详细信息以获取更多信息。" UserInfo = {NSUnderlyingError = 0x6080000565c0 {Error Domain = FIRAuthInternalErrorDomain Code = 3 "(null)" UserInfo = {FIRAuthErrorUserInfoDeserializedResponseKey = { 代码= 400; 错误=( { domain = global; message =" MISSING_PASSWORD&#34 ;; reason =无效; } ); message =" MISSING_PASSWORD&#34 ;; },} error_name = ERROR_INTERNAL_ERROR,NSLocalizedDescription =发生内部错误,打印并检查错误详细信息以获取更多信息。})
NOK。 .errorCodeInternalError
可选(错误域= FIRAuthErrorDomain代码= 17026"密码长度必须为6个字符或更长。" UserInfo = {NSLocalizedDescription =密码长度必须为6个字符或更长。,error_name = ERROR_WEAK_PASSWORD, NSLocalizedFailureReason =密码应至少为6个字符})
.errorCodeWeakPassword被调用。这也没问题。并且也应该是第5点imo
的情况
可选(错误域= FIRAuthErrorDomain代码= 17999"发生内部错误,打印并检查错误详细信息以获取更多信息。" UserInfo = {NSUnderlyingError = 0x600000053ce0 {Error Domain = FIRAuthInternalErrorDomain Code = 3 "(null)" UserInfo = {FIRAuthErrorUserInfoDeserializedResponseKey = { 代码= 400; 错误=( { domain = global; message =" MISSING_EMAIL&#34 ;; reason =无效; } ); message =" MISSING_EMAIL&#34 ;; },} error_name = ERROR_INTERNAL_ERROR,NSLocalizedDescription =发生内部错误,打印并检查错误详细信息以获取更多信息。})
调用NOK内部错误。为什么不和第1点相同?