9

I have a react app with a login page using firebase auth, where i can login using either facebook or google. This works fine, i can display the username and its avatar.

I am using mongodb, for saving other items, and i have a user model where i wish to save some extra data such as country, age etc. Can i in some way combine firebase auth user data with mongodb, so when i create a new user can i then create a new user with mongodb, but later on add extra info such as country, age etc? I guess mongodb would need to match some id with the user id?

What i have tried:

I havent tried the solution above because im unsure if it will work, or if i should just scrap firebase auth, and just use mongodb for my authentication.

  • It's not clear to me the problem you're running into. Of course you can store information about a user in a database using their UID assigned by Firebase Authentication. – Doug Stevenson Apr 14 '19 at 19:39

1 Answers1

10

It is fairly common to store user information in a separate database. Developers do this both for extra properties and to allow querying user profiles from within your app, which the client-side libraries for Firebase Authentication don't allow.

The most common databases for such information are the ones that are part of Firebase itself (Realtime Database, and Cloud Firestore), but it can be stored in MongoDB just as well. The only requirement is that you associate the user profile information in the database with the user profile in Firebase Authentication, typically by using the Firebase Authentication UID of the user as the key in the database.

For some examples of this (typically for Firebase Realtime Database, but the approach is the same for any database), see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807