Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change email in firebase auth?

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.

like image 952
CENT1PEDE Avatar asked Oct 07 '16 05:10

CENT1PEDE


People also ask

Can you change email in Firebase Auth?

FOR FIREBASE V9 (modular) USERS: if any others trying this code please don't forget to re-login (firebase needs recent login token) firebase user. then only firebase will allow to change email address.

How do I delete my Firebase authentication account?

You can also delete users from the Authentication section of the Firebase console, on the Users page. Important: To delete a user, the user must have signed in recently. See Re-authenticate a user.


2 Answers

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]')     }) 
like image 193
Frank van Puffelen Avatar answered Sep 21 '22 14:09

Frank van Puffelen


If someone is looking for updating a user's email via Firebase Admin, it's documented over here and can be performed with:

admin.auth().updateUser(uid, {   email: "[email protected]" }); 
like image 40
Robin Wieruch Avatar answered Sep 20 '22 14:09

Robin Wieruch