We need to create a Firebase project, but we will be using the Authentication feature instead of the Realtime database now. If you already have a Firebase project set up, you can use the Authentication feature for that project.
Sign-in providers
Firebase offers a range of sign-in providers. You can select any one from these.
Here, we will be using the generic authentication flow using the Email/Password sign-in provider. We need to enable this sign-in provider by clicking on it and changing the configuration to enable it. We are using this sign-in provider to mimic our own Authentication API.
Firebase REST API
Now, we need to connect the REST API to handle adding new users and allowing existing users to log in to our web application. This can be done by referring to the docs here.
Registering New Users
With our Firebase authentication set up, we can now add users to our application, and give them appropriate authentication tokens to access protected resources within our web app.
I'll be using a custom hook to set up a fetch request to the Firebase API to add new users via authentication. Here is the custom hook:
After we successfully register a new user to our app, we can see the use with email and password added to our Firebase console:
Firebase automatically creates the Authentication token for each user, which is under the User UID tab.
Existing User Login
After successfully registering a user to our Firebase back-end API, it is time we add the logic to allow already registered users to gain access to the protected resources in our app. We would need to refer these docs.
Sign in with email / password
We will use the same custom HTTP hook that we created before to issue a POST request to verify the password at the verifyPassword API endpoint.