11

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.

1
  • 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. Commented Apr 14, 2019 at 19:39

1 Answer 1

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:

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

1 Comment

Thank you! i think i got the idea now on how to do it :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.