Firebase authentication (email/password) how to set user's uid?

1.3k Views Asked by At

I am authenticating using email/password like so:

firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
 // Handle Errors here.
});

And listening to auth here:

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // User is signed in.
    console.log(user);
  } else {
    // No user is signed in.
    console.log("Not signed in");
  }
});

Which works fine. On examining the user object that auth returns, the uid is a random string, is there a way to set this uid when I create the account? For example, uid="someUserName"?

Thanks

1

There are 1 best solutions below

1
On BEST ANSWER

Firebase Authentication is not like a database where you can add properties and such. It handles UID's and such for you. What you can do, is in your Firebase Database add a users directory and store additional info there (such as a username) with the UID as the key.

Here's an example:
users

If you're going to use this often, it's probably a good idea to go into your database rules and add an index on this username:

rules