How do I store more information in Firebase for a user than the Auth module allows?

前端 未结 1 1471
我寻月下人不归
我寻月下人不归 2021-01-16 02:56

The Authorization module in Firebase only allows me to store a user\'s email and password; but I want to store more information, like: name, phone number, list of games they

1条回答
  •  礼貌的吻别
    2021-01-16 03:33

    Choosing Firebase for data storage is good choice in my view. Because, it is easy to use and less expensive.

    Coming to the problem, you can't set additional data to the authentication table in Firebase console.

    It just shows email and unique user id and doesn't show even password used for registration.

    One of the easy way of storing user information in Firebase is as follows.

    After success of login or signup of user, you will get user's unique id.

    function(error, userData) {
      if (error) {
        console.log("Error creating user:", error);
      } else {
        console.log("Successfully created user account with uid:", userData.uid);
    }
    

    With that user id, you can create an object in Firebase database.

    function(error, userData) {
      if (error) {
        console.log("Error creating user:", error);
      } else {
        var userId = userData.uid;
        var ref = new Firebase('https://docs-examples.firebaseio.com/web/data');
        var userRef = ref.child('users/' + userId);
        userRef.set({
          email: "userEmail",
          name: "userName",
          phoneNumber: "userPhoneNumber",
          password: "userPassword",
          interestedGames: {
             "game1": true,
             "game2": true,
             "game3": true
          }
        });
      }
    

    You can retrieve the data of the user using childRef as I shown above, that you can get when user logs in.

    0 讨论(0)
提交回复
热议问题