I am trying to change/update a user’s email address using :
JavaScript
x
2
1
firebase.auth().changeEmail({oldEmail, newEmail, password}, cb)
2
But I am getting …changeEmail is not a function error. I found the reference here from the old firebase docu.
So how to I do it in the 3.x version? Because I cant find a reference in the new documentation.
Advertisement
Answer
You’re looking for the updateEmail()
method on the firebase.User
object: https://firebase.google.com/docs/reference/js/firebase.User#updateEmail
Since this is on the user object, your user will already have to be signed in. Hence it only requires the password.
Simple usage:
JavaScript
1
6
1
firebase.auth()
2
.signInWithEmailAndPassword('you@domain.example', 'correcthorsebatterystaple')
3
.then(function(userCredential) {
4
userCredential.user.updateEmail('newyou@domain.example')
5
})
6