How to unlink Email from Firebase using Firebase Admin Node JS SDK

Issue

I’m trying to unlink Email to the current user that has a Phone Number and Email already linked to it.

here what I do :

admin.auth().updateUser("user uid", {
  email: null,  
  password: null,
})
.then(function(userRecord) {
    // See the UserRecord reference doc for the contents of userRecord.
    console.log('Successfully updated user', userRecord.toJSON());       
})
.catch(function(error) {
    console.log('Error removing email:', error); 
});

but it was returning error The email address is improperly formatted.

for some reason, only when I remove the email this happen, when i do the same for phone its working :

admin.auth().updateUser("user uid", { 
  phoneNumber: null,
})
.then(function(userRecord) {
    // See the UserRecord reference doc for the contents of userRecord.
    console.log('Successfully updated user', userRecord.toJSON());       
})
.catch(function(error) {
    console.log('Error removing phone number:', error); 
});

The above code works, the phone is removed perfectly. but only when I do this to Email occurring error.

Is there something I miss?

Solution

UpdateRequest#email must be undefined or a valid email.

UpdateRequest#password must be undefined or an unhashed password.

You may be able to use:

admin.auth().updateUser("user uid", {
  email: undefined,  
  password: undefined,
})

But you are often better off unlinking the EmailAuthProvider credential on the client.

firebase.auth().currentUser
  .unlink(firebase.auth.EmailAuthProvider.PROVIDER_ID);

Answered By – samthecodingman

Answer Checked By – Clifford M. (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.