Skip to content
Advertisement

Firebase Auth: Edit UID

Is it possible to to change a user’s UID in Firebase programmatically? There can’t seem to be a way to do so manually within Firebase’s console.

Advertisement

Answer

TL;DR: If you need to specify the UID, you’ll need to create a new user with that UID.

You can’t directly change the UID, but I was able to hack something together using the firebase admin API (docs)

My use case was that I needed to change a user’s email address. I tried update email with “Update a User”, but this actually ended up changing the UID under the hood. In my app, the UID is tied to so much stuff, that I’d have to do a huge architecture change, so this wasn’t an option.

The general way I did this with the API was:

  • Pull Down a user using admin.auth().getUserByEmail
  • Delete the user with admin.auth().deleteUser
  • Create a new user with admin.auth().createUser, using relevant data from the getUserByEmail call above, replacing the email address with the new email.
  • “reset password” in the firebase admin console (I think there’s a way to do this programmatically too)
  • User gets an email to reset their password and they have a new account with their old UID.

Unlike admin.auth().updateUser, createUser actually lets you specify a UID.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement