I would like to authenticate and keep sessions via NodeJS with Firebase. Client can't directly communicate with Firebase.
In short:
Client (browser) <----> NodeJs(firebase-admin) <----> Firebase
I created Firebase client in NodeJS, then I used login method:
var firebaseClient = require('firebase'); firebaseClient.initializeApp(config) firebaseClient.auth().signInWithEmailAndPassword(req.body.email, req.body.password).catch(function(error){ console.log(error); })
and then I created route to check authenticated user:
app.get('/check',function(req,res){ var user = firebaseClient.auth().currentUser console.log(user) })
This method only allows me keep 1 previously logged user.
I would like to use firebase-admin, but I don't know how to keep session and authenticate users
In order to test this, we will have to use Firebase Auth to login a user to our front end, get a AuthToken for that user, then send that token to our server and use Firebase Admin to verify that token. So both the frontend and backend need to be using Firebase.
In the present era, user authentication is one of the most important requirements for Android apps. It is essential to authenticate users, and it is much harder if we have to write all this code on our own. This is done very easily with the help of Firebase.
Firebase has a real-time database feature that allows easy creation of real-time applications such as chat apps. To get started, let's begin by creating a Node. js application using npm init and add the following packages: firebase : this will be used to access and perform actions to our firebase real-time database.
You can authenticate clients on their respective devices/browsers using the client SDK, and them get them to send an ID token to a backend service written using firebase-admin (the admin SDK). The admin SDK provides methods for validating ID tokens sent by clients: https://firebase.google.com/docs/auth/admin/verify-id-tokens
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