问题
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