How to change email in firebase auth?

CENT1PEDE picture CENT1PEDE · Oct 7, 2016 · Viewed 31.4k times · Source

I am trying to change/update a user's email address using :

firebase.auth().changeEmail({oldEmail, newEmail, password}, cb)

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.

Answer

Frank van Puffelen picture Frank van Puffelen · Oct 7, 2016

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:

firebase.auth()
    .signInWithEmailAndPassword('[email protected]', 'correcthorsebatterystaple')
    .then(function(userCredential) {
        userCredential.user.updateEmail('[email protected]')
    })