Sunday, 16 April 2017

NodeJs authentication with firebase

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 node js a 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);
})

a 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



via Karol Bilicki

No comments:

Post a Comment