StrandedSwan
StrandedSwan

Reputation: 43

Should I use the Firebase UID as the primary key for the User table in my database?

I can get the user's Firebase UID on my server from the access token. I want to create a User table in my PostgreSQL database and use the UID from Firebase to find the user in my database.

I could use the UID from Firebase as the primary key of the User table. The advantage of this approach would be that I would have access to the User ID in the token and would not have to make any additional database calls to get it. I'm not sure if there would be downsides to this approach, for example, if I were to swap firebase for another provider in the future, then the IDs could be generated again by another provider. Can you see this being a problem? Is there anything I may not have taken into account? Or would you go ahead with this approach?

Upvotes: 4

Views: 971

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598740

It is fairly common to use UIDs to identify Firebase users in external data sources, as Firebase already ensures/requires that these IDs are unique.

If you think it's realistic that you may switch providers and end up with conflicts, consider either storing an additional "provider type" in your database, or prefixing the UID that you get from Firebase in your own database, like "firebase:37ydfgsd93ehksdkjhdas".

Upvotes: 4

Related Questions