我尝试运行以下内容但它不起作用。如果用户已经使用过该电子邮件,检查Firebase服务器我做错了什么?
FIRAuth.auth()!.createUser(withEmail: self.userEmailTextField.text!, password: self.userPasswordTextField.text!) {(createUser, error) in
if error != nil {
FIRAuth.auth()!.signIn(withEmail: self.userEmailTextField.text!, password: self.userPasswordTextField.text!)
//Display logged in
let viewController = self.storyboard!.instantiateViewController(withIdentifier: "TabBarController") as UIViewController
self.present(viewController, animated: true, completion: nil)
}else {
//Display an alert message
self.displayMyAlertMessage(userMessage: "Email already in use. Please see the login page.")
return
}
}
答案 0 :(得分:4)
请参阅以下代码。
代码:
FIRAuth.auth()?.createUser(withEmail: email, password: password) {
(user, error) in
if (error) {
// Email is already in use.
} else {
// Create new user successfully
}
}
答案 1 :(得分:1)
Firebase已经为您完成此操作。删除登录方法,然后使用已存在的电子邮件运行create user方法,并返回FIRAuthErrorCodeEmailAlreadyInUse
。查看this以获取更多信息