1

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.

Manas Saxena
  • 2,171
  • 6
  • 39
  • 58
  • Aside from Jen's excellent answer: the examples that you give of [user name]() and [profile pic]() are things you can also store in Firebase Authentication directly. See the Firebase documentation for precisely those two examples: https://firebase.google.com/docs/auth/android/manage-users#update_a_users_profile (Android, but it works the same on Web and iOS). – Frank van Puffelen Aug 20 '17 at 20:26

1 Answers1

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.

Jen Person
  • 7,356
  • 22
  • 30
  • I also have an admin user which needs complete access to all users . for example the admin would search a given user and fetch its data. For this I would have to perform a reverse lookup of UId using email right ? – Manas Saxena Aug 21 '17 at 07:46