2

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

shell
  • 1,867
  • 4
  • 23
  • 39

1 Answers1

2

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

xjsc16x
  • 278
  • 1
  • 6
  • 16
  • I see. I wanted to do this because if I have some $user route I would like to do: auth.uid === $user. I suspect you can make some security rule checking if the key is equal to the auth.uid? – shell Dec 15 '16 at 03:38