Okay.
And once we have refactor the auth middleware as well as remove the token from our server responses.
Now it's a remove token from our front end.
Again, let me repeat, I know I've said this 10,000 times.
The reason we can do that is because now Token is located in the cookie.
And the browser is doing all the heavy lifting.
We don't need any more storage token in a state or stored in local storage.
It's not necessary anymore.
Automatically.
If the cookie hasn't expired, it will be sent back with every single request.
Hopefully that is clear.
And yes, please be careful when making these updates.
It's very easy to make a typo and then it's going to be.
Somewhat time consuming to find that bug.
First, what we want to do.
Is remove all instances of this local storage.
Yes, we'll still get back user and user location from the server.
We'll use it.
We'll still store it in the state, but not anymore in the local storage.
So let's start with that.
I'm going to navigate bom bom bom to the app context.
And yes, I'm going to be somewhat annoying by repeating.
Please be careful.
This is what we're removing here and there.
I just see students rushing through the content and then spending a lot of time on basically getting
the bug fixed.
So let's start in the app context, like I just said, and we want to scroll up and notice all these
instances where we basically get the values from local storage.
Once our application starts up, we don't need them anymore.
That's it.
We'll actually get those values directly from the server.
Let's save it up next and then read me.
We want to fix the initial state.
We want to remove the token.
Again, it's not going to be in a state.
We want to set the user equal to null since we have no instances of the local storage anymore.
And when it comes to user location, job, location, both of them are going to be empty strings.
So let's try it.
I'm going to go to my initial state.
I don't need token anymore.
That's it.
We're done.
Then as far as the user, by default, it's going to be null.
Only once we get the values from the server.
Then we'll actually set it.
So no.
Here.
User location.
Empty string.
And the same goes for job location.
So these are the changes that we want to make in the initial state.
Let's keep on moving.
What about the interceptor, the request one?
Well, we don't have the token value in the state anymore, do we?
So there's no need again.
The token is located in the cookie.
Yes, I definitely said this 10,000 times right now, But yes, that's true.
So we don't need to do this anymore.
Let's go to your app context.
Let's keep on scrolling.
So we still have our fetch.
There's nothing wrong with this one.
What we want to do is remove the request one.
So please keep the response one.
We'll still log out the user with 401.
But yeah, we don't need to do this anymore.
So if you want, you can leave the comment in.
Like I said, yes, I'm going to do that.
So let's just remove this sucker.
Let's save and let's keep on moving now.
We want to remove both functions.
Add the local storage.
Remove from local storage.
And also we want to fix the setup user and update user.
Because again, we are not passing the token and we don't want those local storage functions.
And then we'll worry about the reducer.
So let's go here to app context.
Let's keep on moving.
Notice the ADD.
User to local storage.
Nope.
Don't need that anymore.
Or here as well.
And then let's look for that setup user.
Or if you have login or register.
Basically if you didn't refactor it.
Remember, we're getting the data, but now the token is not in the data.
So let's remove it over here.
And then when we dispatch, we also don't want to pass it.
So let's remove it and then add user to local storage.
We don't want to do that anymore.
Again, three places where we have the data.
Where we pass it to the payload and where we add this to a local storage.
Don't have the token anymore.
Let's keep on moving and we want to go to update user.
Again, same deal.
We don't want a token.
We don't want to pass it.
To our future.
And lastly, we don't want to add this to a local storage like so.
So.
That looks about right.
Let me just double check token local storage functions.
Okay.
Now we want to go to reducer and basically remove all the instances of the token.
So let me navigate.
Where is my reducer over here.
So I'm going to use the command f basically look up and I'm going to look for the token.
It says that I have five instances basically in order to set up user success.
Let's remove this again.
We don't have that token anymore.
Let's save it.
I have three instances.
Let's see where I have them on the log off user.
Do I need to set the token equal to No.
No, I don't simply go over here and I just remove token.
And then I have two more.
And that one is when I'm updating the user.
So token equals two payload token.
I don't need that anymore in the update user success.
So those are the first changes that we want to make to the front end application.
And let's just start out again.
Yes, our application is going to break at some point, but don't worry, we'll fix all of those things
in the later videos.
So now let me navigate back.
Let me just refresh just to stay on the safe side.
And it looks like.
Or here.
So remove local storage is not defined and app contact line 129.
That's good to know.
So let me look for line 129, so log out.
User We also want to do this, so let me add this to a read.
Me just so you're aware of this.
So let me copy this and then in the read me, we want to go I guess let's go after all of them, just
say app context and we're going to go with just copy and paste and we just want to remove and let's
just add a comment.
Let's say remove the local storage code, let's save it and then let's navigate back to the app context.
And we want to go with a remove user from the local storage because again, we don't have that function
anymore in our app context.
So let's try this one out again.
Let me refresh.
Let's go over here.
Let's say Joan.
At gmail dot com.
Let's go with.
The password.
Here.
Submit.
Okay, good.
So we have the cookie.
Everything works.
I can see the profile, and I'm not going to do all of the rods, but let me just change this one.
I'm going to say Smith, blah, blah, blah.
Everything works.
So our functionality is going to work because we have a valid token in the valid cookie.
So the cookie hasn't expired nor the JWT has expired.
The problem is going to be once we refresh.
Why?
Well, because we have no local storage anymore.
And remember, our basically protected root.
Going to be looking for what it's going to be looking for to user.
So at the moment we have the user, but we're not grabbing it anymore from the local storage.
So check it out.
Once I refresh, bam, I'm logged out even though I have the valid cookie.
So this is something that we're going to work on right now.
But basically, the end result should be following where should be able to log in.
Should be able to do all of the functionality.
The only difference is going to be that the moment you refresh, we don't have anymore that local storage.
So since we don't have the local storage, we will automatically be logged out from the application
once we refresh.