How to update both email and password with the new Firebase in quick

I am developing an application with a new firebase from google. And I have a problem updating my email and password.

Here is what I have tried.

let currentUser = FIRAuth.auth()?.currentUser currentUser?.updateEmail(email) { error in if let error = error { print(error) } else { // Email updated. currentUser?.updatePassword(password) { error in if let error = error { } else { // Password updated. print("success") } } } } 

But when updating the password, such an error occurs.

"Domain = FIRAuthErrorDomain Code = 17014" This operation is sensitive and requires recent authentication ... "

As I know, we must reconfigure the user after updating the email.

I tried to reconfigure from firebase with this code.

 let user = FIRAuth.auth()?.currentUser var credential: FIRAuthCredential // Prompt the user to re-provide their sign-in credentials user?.reauthenticateWithCredential(credential) { error in if let error = error { // An error happened. } else { // User re-authenticated. } } 

But this error occurs

Credential Variables Used Before Initialization

I know this because I donโ€™t initialize the credentials variable, but I donโ€™t know how to fix it.

Is there anyone who knows the solution?

+5
source share
1 answer

In your editing you did not initialize your FIRAuthCredential ... it should be var credential = FIRAuthCredential() or just use it as below code

 let credential = FIREmailPasswordAuthProvider.credentialWithEmail(email, password: password) user?.reauthenticateWithCredential(credential) { error in if let error = error { // An error happened. } else { // User re-authenticated. } } 
+7
source

All Articles