Referencing authentication db data in real time db firebase

我只是一个虾纸丫 提交于 2020-01-06 04:50:06

问题


I am making a website with login and registration facility using firebase. I have used firebase "Authentication" database to store the registered users.However, "Authentication" database doesnt store anything other then emailid, password and an auto generated UUID.

I need to store more data like username, profile pic etc for a user. I would be using firebase's "real time" database for the same.

My question is what is the best practise to do the same. Should I use the UID as primary key from "authentication" database and keep it as foreign key in my real time database like below:

Authentication db:

Record 1 - Email:abc@test.com; password:somepassword; UID:UID1
Record 2 - Email:abcd@test.com; password:somepassword; UID:UID2

RealTime db structure:

users
|
|--UID1
   |
   |---Name:Amanda
   |---Surname:Waller
   |---age:30
|--UID2
   |
   |---Name:MyName
   |---Surname:Mysurname
   |---age:39

Or is it better to use email id as primary key instead of using firebase's auto-generated UID. Because in sql we do not generally use the autogenerated ids as primary keys.


回答1:


It’s better to use the UID. For one thing, you can’t have periods in keys, so if you use email as a key you’ll have to handle that by replacing them with some other character. Also, some forms of authentication don’t require email, like Twitter. Since you can get the UID easily once the user is authenticated, that’s what I’d recommend.



来源:https://stackoverflow.com/questions/45785935/referencing-authentication-db-data-in-real-time-db-firebase

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