To change a user's password, it says to have them log in again to get fresh credentials. So I logged them in with this function:
Auth.auth().signIn(withEmail: enterEmailTextField.text!, password: enterOldPasswordLabel.text!) { [weak self] authResult, error in
But I get this error: The password is invalid or the user does not have a password.
Yet I can log out and sign back in on the login page and input the exact same input to the exact same function without issue. It makes no sense.
How do I gain a fresh login credential so they can change passwords? Because the method of logging them in again just does not work.
I also tried an alternate approach of using this function to get the credential:
let credential = EmailAuthProvider.credential(withEmail: enterEmailTextField.text!, password: enterOldPasswordLabel.text!)
I print the credential and it's not nil. I then plug it into this function and get the same error described above:
Auth.auth().currentUser?.reauthenticate(with: credential) { [weak self] _, error in
if error != nil {
print("error: \(error!)")
} else {
...
How do you allow a user to change his or her Firebase password in Swift?