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:[email protected]; password:somepassword; UID:UID1 Record 2 - Email:[email protected]; 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
  • 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: firebase.google.com/docs/auth/android/… (Android, but it works the same on Web and iOS). Commented Aug 20, 2017 at 20:26

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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 ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.