[英]How to logout a user before sending a user a verification email in Firebase
[英]Sending a verification email right after user creation in Firebase
當調用下面的代碼時,我收到以下錯誤消息“沒有與此標識符對應的用戶記錄。該用戶可能已被刪除。”
此時用戶不是由上面的代碼創建的嗎? 我正在嘗試使用創建后的驗證電子郵件來驗證新用戶的電子郵件。 謝謝
let saveAction = UIAlertAction(title: "Create",
style: .default) { action in
let emailField = alert.textFields![0]
let passwordField = alert.textFields![1]
Auth.auth().createUser(withEmail: emailField.text!,
password: passwordField.text!) { user, error in
if error == nil {
Auth.auth().signIn(withEmail: self.textFieldLoginEmail.text!,
password: self.textFieldLoginPassword.text!)
}
}
Auth.auth().currentUser?.sendEmailVerification { (error) in
if let error = error
{print("Error when sending Email verification is \(error)")}
}
}
創建用戶時,他們會自動登錄。因此,您可以刪除登錄呼叫,並將驗證電子郵件的發送移至完成處理程序中:
Auth.auth().createUser(withEmail: emailField.text!,
password: passwordField.text!) { user, error in
if error == nil {
Auth.auth().currentUser?.sendEmailVerification { (error) in
if let error = error
....
在無法正常工作的情況下,登錄方法還具有完成處理程序,因此:
Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
if error == nil {
Auth.auth().currentUser?.sendEmailVerification { (error) in
if let error = error
// ...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.