Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to re-authenticate a user with firebase

I have tried to re-authenticate a user with firebase but I can't seem to get it to work. I have looked at the firebase documentation but it wasn't helping me. Here is what I got.

var emailTextField: UITextField!
var currentPasswordTextfield: UITextField!

let reEnterInfo = UIAlertController(title: "Re-Enter Email and Password", message: nil, preferredStyle: .alert)
        reEnterInfo.addTextField(configurationHandler: emailTextField)
        reEnterInfo.addTextField(configurationHandler: currentPasswordTextfield)
        let reSignInButton = UIAlertAction(title: "Re-Sign In", style: .default, handler: self.reSignIn)
        reEnterInfo.addAction(reSignInButton)
        self.present(reEnterInfo, animated: true, completion: nil)

  func reSignIn(alert: UIAlertAction!)
  {
    let user = Auth.auth().currentUser
    let credential: AuthCredential

    user?.reauthenticate(with: credential) { error in
        if error != nil {

        } else {

        }
   }
}

I am trying to re-authenticate to change the user password.

like image 736
Nathan Lorenz Avatar asked Oct 21 '25 05:10

Nathan Lorenz


1 Answers

You need to provide the actual credential:

let credential = EmailAuthProvider.credential(withEmail: email, password: password)
like image 139
ktm125 Avatar answered Oct 24 '25 09:10

ktm125



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!