Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Admin SDK to Log user in from Server

I have been using Firebase Admin SDK in my Node JS code for authenticating users from the server side.

The Admin SDK provides a method admin.auth().createUser() to create new users.

admin.auth().createUser({
        email,
        password,
        displayName: name
    })
    .then(function(user) {
        console.log("Successfully created new user:", user.uid)
        return res.send(user)
    })
    .catch(function(err) {
        console.log("Error creating new user:", err)
        return res.send(err)
    })

But now how to make a user login like there is a method auth.signInWithEmailAndPassword(email, pass) in the Firebase Client SDK.

There is a method on the firebase admin SDK to get the user info by Email admin.auth().getUserByEmail(email). This method returns all the user information including password but that password is hashed. So now is there any workaround to have a proper authenticate users from Server.

like image 359
Osama Xäwãñz Avatar asked Dec 13 '22 15:12

Osama Xäwãñz


1 Answers

My comment is a bit late but one option would be to use the Firebase REST API directly but integrated into your own server-side API for authentication. And then use a combination of that and the Admin SDK to wrap it all up. REST API docs can be found here https://firebase.google.com/docs/reference/rest/auth/#section-sign-in-email-password. You could keep your client light weight and wrap up all Firebase auth stuff, custom claims, login, logout etc. all through your own API. You would just need to use both methods to do so. This would abstract you away from any dependencies in your app and API as you could put it all in a single service provider. Just food for thought.

like image 182
mackie1908 Avatar answered Dec 21 '22 10:12

mackie1908