Swift 电子邮件地址为空时的Firebase FireAuthErrorCode
我正在为Swift 电子邮件地址为空时的Firebase FireAuthErrorCode,swift,firebase,firebase-authentication,Swift,Firebase,Firebase Authentication,我正在为firebase电子邮件和密码注册实施FireAuth错误代码,除了2种情况外,它们都能工作。当电子邮件地址字段为空时,将调用case.errorCodeInvalidEmail。当我键入一些字母(没有有效的电子邮件地址)时,将调用默认大小写。对于密码字段,则相反。当我键入一个字符时,将调用大小写。ErrorCodeWeakPassword。当我将字段留空时,将转到默认大小写 这是我的代码: @IBAction func SignInButtonPressed(_ sender: Log
firebase电子邮件
和密码注册
实施FireAuth错误
代码,除了2种情况外,它们都能工作。当电子邮件地址
字段为空时,将调用case.errorCodeInvalidEmail
。当我键入一些字母(没有有效的电子邮件地址)
时,将调用默认大小写。对于密码字段
,则相反。当我键入一个字符时,将调用大小写。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")
}
}
})
}
})
}
}
我不知道哪个错误代码会处理错误的电子邮件格式或文档中的空密码字段。我可以尝试自己处理它们,但我认为firebase
会涵盖这些情况吗
有人能帮我吗
编辑:在深入挖掘之后,我设法打印出了firebase对错误的描述
总是有错误代码。我会打印
errCode
,而不是硬编码的“默认值“
在默认情况下。但我不想使用默认情况。这太一般化了,您不应该在默认块中处理身份验证错误。因此,您需要为要处理的所有错误代码添加case
块。要找出在什么情况下得到的代码,请扫描您链接的页面(您提到的错误代码有四个以上),或打印默认块中得到的错误代码。请确定还有更多错误代码,但我提到的情况除外。我只是看不到它们。只需打印(错误?.code)
完成块中的任何位置,然后尝试使用无效电子邮件创建用户。您将在控制台中找到代码,使用它在开关
语句中为无效电子邮件编写一个新的案例