Hey, did everybody share?
And in this video, we want to work on a really simple route, which is a kind of a user dashboard.
So here we're calling it as user, but it should be rather a user dashboard.
So let's call this one slash user dash board.
Again, you probably can name it a little bit better.
I'm going to just call it as user dashboard because eventually there will be admin dashboard too.
So this is all what we're going to see the idea behind it that whenever somebody visits this user dashboard
route, he will be able to see all of his personal information, name, email, photo, whatever you
want to send.
Since we have injected this information and request that user, we will be able to extract that.
So let's go ahead and create a route for that.
And this is all what we have done so far.
Let's go ahead and create kind of a copy this one more time and we don't need any of the detail.
So again, why it expanded that we don't want to expand above one so this can shrink it down.
And again, feel free to copy any one of them or create another one.
Doesn't really matter.
We don't really keep any information inside.
I just like to have the above boilerplate code, that's why.
Okay, so this one is going to be information about get logged in user details really long, but it
actually explicitly mentioned what this route or what this method is exactly going to do.
Now this method obviously will be used only by the people who are already logged in.
So the job of the middleware obviously comes in.
We'll handle that into the route part, just like we have done in the past as well.
So let's go ahead and say that, hey, I want to go ahead and grab a user.
So we'll say user dot find command, user, dot find by ID because I can now access the idea of the
user.
It will be coming up directly for me to request that user again.
Request that user doesn't exist.
We have injected this property and we can just access a dot ID by having this one appear so really nice.
I would love to hold this into available, so let's go ahead and call this one as into user.
Since database is always on another continent, we stored that and that's it.
That's all it takes.
Now we're going to go ahead and say resort status told you really really easy that JSON and inside the
JSON the classic success of true and we are also going to send the user as it is okay now anybody can
actually request this route and we can actually work on with that, but we don't want anybody to access
that.
First, let's go ahead and use this route into the routes.
So where are my routes here?
Our user routes.
Let's first go ahead and add this method and now let's create a route for this one.
So we'll duplicate this one and we're going to call this one as simply user dashboard.
Now, this can be really a simple get route since we are not sending any information, it doesn't need
to be a post route.
It can be a simple get route and not like that.
There we go.
And obviously the method that will be controlling this is going to be this one.
First, this should be all okay and I should be able to visit this route because we are not predicting
it right now.
So let's go ahead and kind of save as and this one will be user dashboard.
Let's go ahead and save this one.
This is going to be a get route.
So let's save this one.
And the route that you'll be visiting up is user dashboard.
So this should be all good.
And let's go ahead and send this one.
And it says, hey, I cannot read the property of undefined.
So looks like something is missing.
So it's not able to read the token from the cookie or something.
Let's go ahead and see out what is the issue that is it says cannot read the property ID of undefined.
Let's see that where we are missing this one.
Oh really really my bad.
Two too bad of a this of error.
Now the reason why it's not able to see this ID because we haven't injected the ID, so obviously we
need to inject something in this root in between so that there is something that it can work on with
that.
So obviously we need to bring in now our middleware and inject this middleware so that it can check
in whether this ID exists or not and all of that.
So without this injecting the middleware, this obviously is not going to work.
So let's go ahead and import that.
So this is our middleware.
We are calling it as is logged in.
Let's see if the auto input works.
So is logged in.
Yeah, really nice.
I love that.
So it is logged in is now working.
So what we're going to do is let's cut this out and since this is just a method that we have to run
and let me just quickly check.
This is a method itself, so we don't need to worry.
Now, before the get request actually comes up onto this load and this method takes control, we're
going to just paste this one, have a comma, and that's it.
So now the request will first go to is logged in and we are going to verify that whether is this user
is able to access this dashboard or not and then this request goes in there.
So hopefully in theory, this should work.
Now let's go ahead and check it one more time and we are using this user dashboard.
Let's go ahead and send this one and let's see that what we are receiving in the body.
So we are receiving all success, the user, the ID, secure ID, the idea of the user, name, email,
roll, whatever is there, it's coming in.
Most importantly, this is not all the check that we have done.
Now we need to log out.
So let's go ahead and send a log out and it says it is going to log in.
Come on, it should be log out.
Save that.
Okay, now let's go ahead and log out.
Okay.
So log out is success.
This means that now if I check into the cookies, there is there shouldn't be nothing up here because
this is the t shirt store environment variable.
So let's go ahead and log out one more time.
And here the cookies are all going out.
But this one is not yet refreshed.
So I need to probably somehow.
How can I refresh this?
I have no idea.
Let's go ahead and try to send this one.
Okay.
So it says no cookies yet.
So this time it got refreshed and in the body it says JSON web token error JWT malformed.
So here errors need to be taken care a little bit better.
But again, the idea is that we should be able to do this properly a little bit better.
But the whole idea is we are not receiving any of the data data.
So this is all good.
We are not receiving any of the token.
Okay.
Now, one more interesting thing that I would like to mention here.
As I told you, that sometimes token might not go into the cookie itself, token might go into authorization.
So let's go ahead and check out that.
So in this, log in or sign up.
Now, we are not having any of that, so let's go ahead and have this one as a login.
Again, why are we not having anything inside the body of the login?
Nothing here as well.
Again, I think we are done for now.
Let's go ahead and try to get the user one more time by logging in.
I will go into the body roar.
Jason, let's go ahead and work on with that.
So this one is going to have an email.
That email will be to add the date ae dot dev.
This should be saved up all for me.
I shouldn't be writing this all over the place.
And the password is going to be one, one, two, two, three, three.
And let's send this one.
So there we go.
Now, what I'm going to do is I'm going to go ahead and copy this token.
And now I will send a log out request.
So this should be all saved.
And this is going to send.
A log out requests.
Everything is all cleared out in our user dashboard.
If I go ahead and send this again, we are receiving the same errors.
That is exactly what we want.
But what I want to check out is inside the headers, if I can actually go ahead and send a beta token
there.
So there we go.
I can say beta space and the token and send this one and notice that I I'm also am receiving the data.
So this was a point of checking whether things are working on mobile or not because in the mobile things
might not come from the cookie.
It might be absolutely clean, it might come up from the authorization and the beta token.
Again, you can use this authorization and can say, Hey, I want to send a beta token.
This will do exactly the same thing.
So just to mention that yeah, there are sometimes multiple places due to the exact same thing.
It again gives you exact same thing.
Okay, so this means things are working good and working fine and our Morgan is also working absolutely
fine.
Our errors could do a little bit better job than this one.
We can actually grab this exact error that if the error type is this, then go ahead and say, hey,
this is something and this is something.
But again, not too much where it at this point of time.
Okay, let's see what else we have to do.
Okay.
Now we have to work on some of the put requests that maybe user is logged in and want to update this
password or update rest of the things like email, maybe something else.
Let's go ahead and catch up in the next video.