I'm developing app with new firebase from google. And I'm having problem with updating user email and password.
Here's what I've 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 password this occurs error like this.
"Domain=FIRAuthErrorDomain Code=17014 "This operation is sensitive and requires recent authentication..."
As I know we have to re-configure user after updating email.
I tried with this code for re-cofiguring from the firebase.
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 occurs error
Variable 'credential' used before being initialed
I know this is because I don't initialize 'credential' variable but I don't know how to fix this to work.
Is there anybody who knows solution?
Open your project in the Firebase console. Go to the Email Templates page in the Auth section. In any of the Email Types entries, click the pencil icon to edit the email template. Click customize action URL, and specify the URL to your custom email action handler.
One way to allow your users to change their password is to show a dialog where they enter their current password and the new password they'd like. You then sign in (or re-authenticate) the user with the current passwordand call updatePassword() to update it.
By default, Firebase uses a modified Firebase version of the scrypt hashing algorithm to store passwords. Importing passwords hashed with modified scrypt is useful for migrating users from another existing Firebase project.
In your edit you didn't initialize your FIRAuthCredential
... it should be var credential = FIRAuthCredential()
or simply use it like 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.
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With