Search code examples
pythonfirebase-authenticationfirebase-admin

firebase auth sdk login user with email and passworrd


I'm using firebase auth sdk for an application and I'd like to log the user in. I cannot understand how it works.

To create a new user I run this code:

from firebase_admin import auth

....

def create_user(email, password):
    user = auth.create_user(email=email, password=password)
    return user

Now I'd like to log the user in. The auth doesn't have a method to log in the user. It has a auth.get_user_by_email(email) or some other methods to get user(s), but it has no method to check user's password. My application (API) gets email and password and I need to return the user if the email and password match.

How do I do this using the firebase sdk?

Thank you.


Solution

  • Logging into Firebase happens on the client, not on the server. So the Firebase Admin SDKs don't have a method to sign the user in, but all client-side SDKs (such as the Web/JavaScript SDK) have methods to sign in the user.

    If you want to sign in a specific user from your Python code, you can call the REST API, or use a library like Pyrebase that wraps this REST API: https://github.com/thisbejim/Pyrebase#authentication.