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?
答案 0 :(得分:2)
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
答案 1 :(得分:0)
我会使用第二种方法,但使用自动生成的序列作为键。请记住,UID和用户名可能会随时间而变化。在这种情况下,您必须删除您的记录并重新创建它以获得新的UID /名称。什么可能导致其他问题,例如UID / Name可能是其他关系的一部分。