Ad

Cannot Re Auth User To Change Email Or Reset Password (Firebase.. Swift)

I cannot comment on answers so I have to ask this question, I apologize.

I am getting an error on Xcode when trying to re authenticate the user so their email and or password is changed.

Here is the code I've written.


    var credential: AuthCredential

    let user = Auth.auth().currentUser
            // re authenticate the user
        user?.reauthenticate(with: credential) { error in
            if let error = error {
                // An error happened.
            } else {
                // User re-authenticated.
            }
        }


        }

I get an error that states Cannot convert value of type '(_) -> ()' to expected argument type 'AuthDataResultCallback?' (aka 'Optional<(Optional, Optional) -> ()>')

Ad

Answer

It looks like the reauthenticate function returns a tuple, so you have to change the code:

var credential: AuthCredential

let user = Auth.auth().currentUser

// re authenticate the user
user?.reauthenticate(with: credential) { (authDataResult, error) in
    if let error = error {
        // An error happened.
    } else {
        // Use `user` property of result to check is successful.
    }
}

AuthDataResultCallback

FIRAuthDataResult

Ad
source: stackoverflow.com
Ad