2017-07-30 23 views
0

調用下面的代碼時,出現以下錯誤消息 「沒有與此標識符對應的用戶記錄,用戶可能已被刪除。
是不是由上面的代碼創建的用戶在那一點上? 我試圖在創建後使用驗證電子郵件驗證新用戶的電子郵件。 感謝在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)")} 
            } 

                 } 

回答

1

當你創建一個用戶,它們會自動登錄所以,你可以刪除登錄通話和移動驗證郵件的發送到完成處理程序:

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 
     // ... 
} 
+0

非常感謝你弗蘭克。剛剛意識到我在創作後也有簽字。你的第一個解決方案奏效 – user2867432

相關問題