The right way to store users in a Firebase database

I am currently working on a database layout for my Firebase database. I look at a lot of different guides about how layouts should look, but I'm a little confused about the correctness.

I'm not sure if users should be saved, let me give an example:

{
  "users": {
    "alanisawesome": {
      "nickname": "Alan The Machine"
    },
    "gracehop": {
      "nickname": "Amazing Grace"
    }
  }
}

In the above example, from Firebase Legacy documents, they store users by their usernames. However, in another example, I found the following:

{
  "users": {
    "123": {
      "name": "Kato"
    },
    "234": {
      "name": "Anant"
    }
  }
}

Here they store users with a UID. Then you can just just push()new users, and their identifiers are random keys, such as -JRHTHaKuITFIhnj02kE.

? , UID ?

+4
1

Push-Firebase , , , . , , - ..

, . , uid. , uid. uid, : ref.child('users').child(user.uid). (, push), , .

, , . , push ID, UID , . , .

+11

Source: https://habr.com/ru/post/1650680/


All Articles