All right, and once we can successfully invoke the instant method, now, let's start talking about
the tokens, more specifically JSON with tokens.
And before we install the package and going to these functions and all the nitty gritty stuff.
Let me give you a brief general overview, just so we all are on the same page and be mentored years
following where we're building the application, where user will be able to register and log in, and
then he or she can create job applications and then keep track of them.
Correct.
And that's the main goal.
Now the key thing here is that I don't want anybody else to access my data, so only the user that creates
that specific job can see the job and modify the job.
And that's a very important part of the application.
So how do we restrict that?
Well, we use something called tokens, where essentially if I'm going to open up the death tolls,
more specifically, I'm looking for a network request because I want to show you something.
And if I go to my login, provide my dummy values, you notice something really interesting as far as
our response.
So hopefully my password was correct.
Yep.
I was able to log in, and if I take a look at the login request, one that I'm making out here and
don't worry about starts right now, that's talking about the logging one.
You'll notice this response.
So this is the token that we're sending back.
More specifically, that is a JSON web token and our storage token on a front frontend in two places,
which you'll notice the token is in the React state.
So it's going to be over here.
Notice here, I have the user.
So this is going to be the data that we're sending back in response, but also in response.
We have the token and we set this token equal to a state value.
And then another place where we'll save that one.
And let me find the application and then more specifically, local storage.
Now this will be saving those values there as well.
So that's the first step.
Every time the user registers or he or she Alakazam will send back this token.
And then once we send back the token now with every future request, we'll be sending back this token
to the server and on the server will validate that token.
And you can kind of make an argument, well, we could come up with just some random strings here,
and you're kind of correct, but that would be very easy to break.
Not is the whole point of the aegis and token.
But the idea, yes, would be exactly the same where once the user shows up to the server.
For a registered logging, you just send back some random value and then you just check whether the
value matches, but of course, devotees are way more secure.
And now let me showcase the other thing where once we have logged in, noticed this request.
So pretty much as the user is going to be navigating around our application, he or she is going to
be making those requests.
Whether that is to have a job, maybe that is going to be when he or she wants to modify the profile
and maybe take a look at all the jobs and what you'll notice that with those requests in the headers,
what we're doing from the frontend, we're sending that token back.
So these are going to be response headers for whatever we're looking for.
Here is this one.
Notice the request headers and now is the authorization.
Now this bearer, I want to talk about it once we get there, but this is the one that we're sending
back.
So hopefully this is clear.
That it is all the time this communication between the server and the frontend.
And remember that the DP is stateless, meaning just because I got the token the first time.
If I don't provide in my future requests, I'll actually will fail.
And let me showcase that by going to the local storage, removing the token from the local storage and
then refresh the page and what you'll notice that the moment we refresh the page, the state will be
empty.
That's just the default behavior.
Remember, we cannot persist the value between the refreshes.
That's why we would use something like local storage.
And then since the token is not going to be present, I'll be automatically logged out.
So let me go to my local storage and here let me just clear everything and once I refresh.
What are you doing?
I got logged out.
Why?
Well, let's take a look at the network here.
Notice I have the stats one and the responses for one basically on authenticated error.
And hopefully this gives you a good idea of the overall setup and why we're using the tokens, more
specifically JWT tokens in the first place.