0
votes

I want to verify users that sign in with email and password with a verification email in firebase.

this is my code:

@IBAction func Login(_ sender: Any) {
    guard let email = txtUser.text, email != "",
        let password = txtPass.text, password != ""
        else {
            AlertController.showAlert(self, title: "Missing Info", message: "Please fill out all required fields")
            return
        }
    Auth.auth().signIn(withEmail: txtUser.text!, password: txtPass.text!, completion: { (authResult,error) in
        if error != nil{
            AlertController.showAlert(self, title: "Error", message: error!.localizedDescription)
        } else if authResult != nil {
            self.performSegue(withIdentifier: "SegueMode", sender: self)
        }
    })
}
2
And what's wrong with your code? What's your question?Larme
In my code,Can not verify user this sign in with email and password with a verification email in firebase.@LarmeLalita Senaktang
Can you clarify what you're asking? It sounds like once the user signs in with email and password, you then want to send a verification email? If that's so, there's nothing in that code that attempts to do that. If not, then what are you asking?Jay

2 Answers

0
votes

Have you tried this

Auth.auth().sendSignInLink(toEmail:email,
                           actionCodeSettings: actionCodeSettings) { error in
  // ...
    if let error = error {
      self.showMessagePrompt(error.localizedDescription)
      return
    }
    // The link was successfully sent. Inform the user.
    // Save the email locally so you don't need to ask the user for it again
    // if they open the link on the same device.
    UserDefaults.standard.set(email, forKey: "Email")
    self.showMessagePrompt("Check your email for link")
    // ...
}
0
votes

Here is Function that i used in my project (Note: Change according to your requirement!)

 func loginUser() {

    guard let email = txtUserName.text, let password = txtPassword.text else  { return }

    Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
        if let error = error {
            print(error.localizedDescription)
            self.lblSuccess.isHidden = false
            self.lblSuccess.textColor = UIColor.red
            self.lblSuccess.text = "Invalid Credential Please Check Your Email and password"

        }else if let user = Auth.auth().currentUser {
            let listVC = self.storyboard?.instantiateViewController(withIdentifier: "UserListVC") as! UserListVC
            print(user)
            self.lblSuccess.isHidden = false
            self.lblSuccess.textColor = UIColor.green
            self.lblSuccess.text = "Login SuccessFully!!"
            self.navigationController?.pushViewController(listVC, animated: true)
        }
    })
}