gpt4 book ai didi

ios - Firebase 电子邮件验证 Swift

转载 作者:行者123 更新时间:2023-11-28 11:54:10 26 4
gpt4 key购买 nike

我尝试使用 Firebase 身份验证,但即使我没有使用电子邮件来确认验证,在登录时也会让我进入。我有两个 Viewcontroller ,一个用于登录,另一个用于注册。我可以登录并收到用于验证的电子邮件,但我也可以在不验证的情况下登录。

public func sendVerificationMail() {
if self.authUser != nil && !self.authUser!.isEmailVerified {
self.authUser!.sendEmailVerification(completion: { (error) in
// Notify the user that the mail has sent or couldn't because of an error.
})
} else {
// Either the user is not available, or the user is already verified.
}
}

@IBAction func signupButtonTapped(_ sender: Any) {
print("Sign up button tapped")
Auth.auth().createUser(withEmail: self.userEmailTextField.text!, password: self.userPasswordTextField.text!) { (user, error) in
if user != nil {
print("User has Signed Up")
self.sendVerificationMail()
}
if error != nil {
print("User cant Sign Up")
}
}
}

@IBAction func signinButtonTapped(_ sender: Any) {
Auth.auth().signIn(withEmail: self.userEmailTextField.text!, password: self.userPasswordTextField.text!) { (user, error) in
if user != nil {
print("User has Signed In")
}
if error != nil {
print("Cant Sign in user")
} else {
self.performSegue(withIdentifier: "toHome", sender: nil)
}
}
}

最佳答案

Firebase Auth 不会阻止人们在其电子邮件未经验证时登录。如果您想阻止用户在未经验证时继续前进,您需要使用 isEmailVerified bool 值在客户端对此进行编码。

Auth.auth().signIn(withEmail: self.userEmailTextField.text!, password: self.userPasswordTextField.text!) { (authResult, error) in
if let authResult = authResult {
let user = authResult.user
print("User has Signed In")
if user.isEmailVerified {
self.performSegue(withIdentifier: "toHome", sender: nil)
} else {
// do whatever you want to do when user isn't verified
}
}
if let error = error {
print("Cant Sign in user")
}
}

关于ios - Firebase 电子邮件验证 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51388655/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com