How to verify a user's email address on iOS with Firebase?

前端 未结 2 1243
死守一世寂寞
死守一世寂寞 2021-02-01 11:12

I\'m stuck with email verification with firebase. I\'ve looked around for guidance but no help. After the user verifies his email, my code still prints out the user has not been

2条回答
  •  野性不改
    2021-02-01 11:44

    You checked if the user email was verified even before signing them in.

    This is what worked for me.

        FIRAuth.auth()?.signInWithEmail(txtUsername.text!, password: txtPassword.text!) {
            (user, error) in
            if let user = FIRAuth.auth()?.currentUser {
                if !user.emailVerified{
                    let alertVC = UIAlertController(title: "Error", message: "Sorry. Your email address has not yet been verified. Do you want us to send another verification email to \(self.txtUsername.text).", preferredStyle: .Alert)
                    let alertActionOkay = UIAlertAction(title: "Okay", style: .Default) {
                        (_) in
                            user.sendEmailVerificationWithCompletion(nil)
                    }
                    let alertActionCancel = UIAlertAction(title: "Cancel", style: .Default, handler: nil)
    
                    alertVC.addAction(alertActionOkay)
                    alertVC.addAction(alertActionCancel)
                    self.presentViewController(alertVC, animated: true, completion: nil)
                } else {
                    print ("Email verified. Signing in...")
                }
            }
        }
    

提交回复
热议问题