Hi and welcome back.
Today we're going to discuss a general
architecture of authenticating users, making them able to register on our
application and login into our application.
So imagine that here is our react native
application and we want to register the user.
If we want to register the user,
we're going to have to gather information from them, such as email and password.
Once we do that, we are going to send that data over
to the Firebase API and then Firebase API will receive this data and let us know
whether the user successfully registered with their entered information or not.
If any kind of error occurs, such as this kind of email already exists
in our database, or they didn't enter the correct email
address and their email address doesn't exist, we're going to show the user
an error and they are going to try to register again.
However, if they successfully registered, this information is going to be written
inside the authentication database of the Firebase and we are just going
to bring them to the login page so that they can log in.
Now let's talk about how logging in would work.
When the user tries to log in,
we're gathering the information as they enter their credentials and then we're
going to send that data over using the Firebase API.
And once the Firebase API receives this data, we're going to receive a response
back from Firebase and we're going to know if they successfully logged in or not.
Firebase is going to go and check the database and make sure
that the password and the email that user entered actually exists and is valid.
If it is not valid, then we're going to show the user what
kind of error we got and they are probably going to try to log in again.
However, if the successfully log in,
we are going to receive a token from the Firebase.
So let's talk about what a token is. In Firebase authentication,
a token is a secure string of characters
that serves as a proof of authentication for a user.
When a user successfully logs in or signs
up using Firebase authentication, firebase will generate a token for that user.
And the token itself has several important functions.
First of all, the token includes information about
the user's authentication status and privileges.
It allows the user to access protected
resources and perform actions that require authentication,
such as accessing restricted data or performing write operations.
In our donation application, for example,
user won't be able to donate money unless they are registered.
And if they will want to access those
pages, then they're going to have to be registered and logged in.
The other functionality of Firebase tokens are that it is designed to be stateless.
This means that the server doesn't need
to maintain session information for each user.
Instead, the token itself will contain all the necessary information to authenticate
the user and validate their access to resources.
This reduces the server's overhead and simplifies the authentication process.
The third benefit of having the tokens is that when a user makes requests
to Firebase services, the token is included in the request headers.
This token is encrypted and transmitted securely over Https.
Firebase servers then verify the token's authenticity and integrity,
ensuring that only authenticated users can access the requested resources.
Now there comes a step when the token will expire that was generated using Firebase.
Usually it is just 1 hour, but you can also modify and set your own
expectations on how long should the token be valid.
So if a token expires,
we are going to refresh the token and keep the user logged in.
Firebase tokens have an expiration time to enhance security.
When a token nears expiration,
Firebase provides mechanisms to automatically refresh the token without
requiring the user to reenter their credentials.
This allows for a seamless user experience
and ensures continuous access to resources.
So if the token doesn't expire, we are just going to keep the user logged in.
Overall, the token plays a vital role in Firebase authentication.
By providing secure and verifiable proof of user's identity.
It enables authorization, statelessness
and secure communication between the client application and Firebase servers.
Understanding and utilizing Firebase tokens correctly is essential for building
secure and scalable applications that leverage Firebase authentication.
Now, if the user wants to log out,
then they're just going to click on the button
to do so. We're going to contact Firebase and we're
going to call their sign out API which will dump the token automatically.
And then we're just going to reset the token in our stores and call
the logout function so that they are redirected back to the login page.
So this is the main architecture of how registering, logging in and logging out
works in react native when we're using Firebase.
So in the upcoming videos we're going to utilize this architecture and we are
going to make login and registration that is actually working for the user.
And you're going to be able to use this
knowledge in your application to easily and simply make sure that your application
is secure and that your users are able to register and log in seamlessly.
Thank you so much for watching.
See you in the next video.