Reputation: 20348
I am currently using Firebase for storing the data of my users. It's not a social networking app, but we want to have a slight touch of social networking in our app too, such as adding friends and following what they are doing.
My current Firebase database structure uses UID (Obtained from Firebase Auth) as the key to user's data. Consider the following structure for clarification -
-> users
-> UID
-> name
-> phone
-> email
The problem with this approach is the user can't remember the UID and the app will have to manage the user following. I am now considering a different way to store the data using usernames, just like Facebook or Twitter
-> users
-> UserName
-> UID
-> name
-> phone
-> email
This method needs some code rewrite. We can do that since we're still at pre-Alpha phase and can afford to invest time on it, if it's worth the effort. All the firebase docs and discussion suggest the first approach, but never even mention about the second approach.
So the question is, is it required to follow the username approach if the application have social networking feature? Or should we go with the firebase docs, so as to not break anything, in case Firebase decides to introduce new features.
What could be the possible benefits of staying with the first approach?
Upvotes: 1
Views: 627
Reputation: 1335
I would use the second approach but with a auto generated sequence as key. Keep in mind that UIDs and user names can change over time. In such a scenario you would have to delete your record and re-create it just to have new UID/Name. What could lead to others issues e.g. the UID/Name could be part of other relationship.
Upvotes: 0
Reputation: 1445
You should definitely stick to the firebase guideline. Consider when user will change the username and other problems.
https://www.firebase.com/docs/web/guide/structuring-data.html
You can achieve the business requirement by simply creating lookup.
-> users
-> UID
-> name
-> phone
-> email
-> usersByName
-> UserName: UID
Correct me if I am wrong but only by using pattern like this you can ensure that UserNames will be Unique in Firebase.
Request to www.yoursite.com/user/UserName Can render same content as www.yoursite.com/user/UID Or you can redirect in your application to www.yoursite.com/user/UserName url when requested by UID
Upvotes: 2