We are all done with our sign in and sign up.
Root handlers.
We're not gonna start to move on to a current user.
It's inside my rat's directory.
Often the current user t s file let me first begin by telling you the goal of this root handler.
So here's what we're going to try to implement at some point time a react application is going to need
to figure out whether or not the user is signed into our application.
The react application that can not directly look at the cookie and tried to inspect and decide whether
or not there is a valid JS on web token inside there.
We have set up our cookies in such a way that they can not be actually executed or accessed from javascript
running inside the browser.
So instead the react application needs to be able to make a request to something inside of our app to
figure out whether or not the user is currently logged in and that is the goal of this current user
route.
HANDLER So at some point time or react application is going to make requests to figure out who the current
user is or essentially whether or not the user is logged in.
That request is going to include a cookie if it exists.
So we are going to get a cookie with this incoming request.
Maybe if the user is not logged in There Will Be No cookie but if they are logged in there will be a
cookie present so inside of our off service or more specifically inside of this current user root handler
we're going to take a look at that req not session dot J W T property so remember that is where we are
going to see our Jason web token show up so if the cookie is set there will be a Jason web token there.
If the cookie is not set.
Chances are there will not be a Jason web token so we're going to then take a look at that property
if it is not set or if for some reason that just on a Web token is invalid then we're going to return
early and we're going to send back a response it looks like this otherwise if there is a Jason web token
set on that session and the Jason web token is valid then we're going to send back the payload that
is stored inside the Jason web token.
So it's going to look something like this right here.
We're going to provide an object with a current user property and then for current user we're going
to put in the payload from the Jason web token so that's the general idea.
You'll notice I put this diagram.
I said if the Jason web token is invalid or valid remember at any given point in time a user can't technically
tried to mess around with her Jason web token.
They can try to manipulate the information inside there and pretend that they are some other user or
change their email address or something like that but because we have set up this secure signature thing
which is on a Web token we're going to be able to very easily detect if the Jason web token has been
manipulated in any way.
So if it has been manipulated that's the case in which we will just return early and say Sorry you're
not logged in your Jason web token doesn't really look that all that valid OK.
So it's all this in mind.
Let's take a quick pause right here.
We get back to the next video but all this implementation together inside of our current user root handler.