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.
While MongoDB Realm offers a built-in authentication mechanism, I personally prefer to use Google's Firebase authentication method. It is pretty simple to integrate Firebase with MongoDB Realm for authentication if you know how.
If you want to add additional data, you need to create a model class for your user and then store it in your Firebase database. What about using the setDisplayName method to store custom fields as a JSON Object like this example {"display_name": "User 1", "age": 25, "gender": "Male", "points": 5371} ?
Firebase Authentication provides backend services, easy-to-use SDKs, and ready-made UI libraries to authenticate users to your app. It supports authentication using passwords, phone numbers, popular federated identity providers like Google, Facebook and Twitter, and more.
User properties Firebase users have a fixed set of basic properties—a unique ID, a primary email address, a name and a photo URL—stored in the project's user database, that can be updated by the user (iOS, Android, web).
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With