Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Firebase Authentication service and have user in our own database?

I have my own node.js server setup so I don't need Firebase storage and real-time database service. From the client side (mainly Android) I am trying to authenticate the user using Firebase Authentication service(G+ and FB login) but that creates users in firebase database. How can I create users in my database also?

Currently, I am simply sending user id created by Firebase to my server and saving it in DB and generating a JWT to validate subsequent REST API requests to my server.

like image 615
Praveena Avatar asked Nov 03 '16 20:11

Praveena


People also ask

Can you create a user with the same credentials in Firebase?

Firebase account linking allows users to sign into the same account using different authentication providers. By linking the user's Facebook and Twitter credentials, for example, the user can sign into the same account using either sign-in provider.

Can you add users to Firebase?

Adding members to your Firebase project allows you to collaborate across your team. You can assign each member a role based on the level of access the member needs for your project. Project members are not limited to just individual users: domains, groups, and service accounts can all be members of a Firebase project.


1 Answers

Your client app will get back a Firebase JWT token after end users login with Google/Facebook. Whenever your app needs to send REST API requests to your server, just append the Firebase JWT token into the request body.

On your server, you first validate the Firebase token inside the incoming request. Once the JWT security check passes (signature, audience, expiration etc.), you can extract the 'sub' field (which is the user_id) in the token, and create a user record in your DB only if the user_id is not in DB yet.

like image 190
Jin Liu Avatar answered Oct 07 '22 17:10

Jin Liu