Chris B
Chris B

Reputation: 3

Error reauthenticating user with Firebase / Xcode (for user email update)

I'm trying to create an "update email" screen for an iOS app, using Xcode Version 10.2.1 and Firebase. All of the code for updating the email with Firebase works fine, but I'm getting the following error when I try to reauthenticate the user:

Cannot convert value of type '(_) -> ()' to expected argument type 'AuthDataResultCallback?' (aka 'Optional<(Optional, Optional) -> ()>')

Oh, and I'm using Email credentials to Auth users.

I've searched multiple threads here and scoured through the Firebase documentation and can't seem to figure out what is causing this error.

Here's my code, which I pulled from the Firebase Documentation, as well as this thread:

let user = Auth.auth().currentUser
var credential: AuthCredential = EmailAuthProvider.credential(withEmail: "email", password: "pass")

user?.reauthenticate(with: credential) { error in
     if let error = error {
        // error handled here
     } else {
        // success
     }
}

The error is showing up on the "user?.reauthenticate(with: credential) { error in " line.

Anyone have any idea what is causing this?

(And, apologies if I'm missing something obvious. I'm relatively new to working with Swift/Xcode. )

THANKS!!

Upvotes: 0

Views: 247

Answers (1)

Jay
Jay

Reputation: 35659

I think you're missing the result parameter

let user = Auth.auth().currentUser
var credential: AuthCredential = EmailAuthProvider.credential(withEmail: "email", password: "pass")

user?.reauthenticate(with: credential) { result, error in
     if let error = error {
        // error handled here
     } else {
        // success
     }
}

where result is an AuthDataResult that contains the result of a successful signin.

Upvotes: 0

Related Questions