我有以下代码来将用户注册到 firebase...
FIRAuth.auth()?.createUserWithEmail(email.text!, password: password.text!) {(user, error) in
if let error = error {
print(error.localizedDescription)
if error.localizedDescription == "FIRAuthErrorCodeEmailAlreadyInUse"
{
//sign in here?
}
}
else {
print("User signed in!")
}
} }
else{
print("You left email/password empty")
}
如果用户已经创建,我需要添加什么才能自动登录?
谢谢。
最佳答案
您可以使用 Firebase 提供的任何身份验证方法。例如。对于您的情况,这个最合适:
Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
// ...
}
编辑
您发布的注册方法的错误响应将告诉您给定的用户是否已存在。在这种情况下,您可以从回调中自动调用signIn方法。
查看official docs ,我看到您应该查找的错误代码是 FIRAuthErrorCodeEmailAlreadyInUse。
关于ios - 将用户注册到 firebase 并登录(如果已注册),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45490376/