Dawood Muzammil
Dawood Muzammil

Reputation: 21

Firebase Authentication Microservice

I am trying to write a REST microservice in Node.js that would deal with user authentication (among some other things) requests coming from different platforms.

What I would like is for the device to remember which user is signed in and keep the session for itself only. What currently happening is that I am able to login only one user at a time; if another user logs in from another device, the new user is returned as the currentUser. It's my first time using Firebase Authentication so I am very confused.

Here's the code for the login endpoint:

async signInUser( req, res, next ) {
    var user = firebase.auth().currentUser;

    if ( !user) {
        var email = req.body.email;
        var password = req.body.password;

        // sign user in: if login fails, send error message as response
        user = await firebase.auth().signInWithEmailAndPassword( email, password)
                        .catch( function( error) {
                            res.send( error.message);
                        });
    }
    // login successful: send user object as response
    res.send( user);        
}

Upvotes: 0

Views: 1239

Answers (1)

Mani Ezhumalai
Mani Ezhumalai

Reputation: 469

Firebase have custom authentication you can pass your user unique id to firebase and genrate token for perticular user so you can able create unique session for different user and you can refer below link

https://firebase.google.com/docs/auth/admin/create-custom-tokens

Upvotes: 2

Related Questions