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

强颜欢笑 提交于 2020-03-03 04:28:02

问题


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:


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:

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:



来源:https://stackoverflow.com/questions/41155905/firebase-authentication-email-password-how-to-set-users-uid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!