WEBVTT

00:03.840 --> 00:05.310
Hey, did everybody share?

00:05.310 --> 00:09.510
And in this video, we want to work on a really simple route, which is a kind of a user dashboard.

00:09.510 --> 00:14.820
So here we're calling it as user, but it should be rather a user dashboard.

00:14.820 --> 00:20.730
So let's call this one slash user dash board.

00:20.760 --> 00:23.400
Again, you probably can name it a little bit better.

00:23.400 --> 00:27.360
I'm going to just call it as user dashboard because eventually there will be admin dashboard too.

00:27.360 --> 00:33.000
So this is all what we're going to see the idea behind it that whenever somebody visits this user dashboard

00:33.000 --> 00:37.440
route, he will be able to see all of his personal information, name, email, photo, whatever you

00:37.440 --> 00:38.160
want to send.

00:38.370 --> 00:43.020
Since we have injected this information and request that user, we will be able to extract that.

00:43.020 --> 00:45.300
So let's go ahead and create a route for that.

00:45.570 --> 00:47.550
And this is all what we have done so far.

00:47.550 --> 00:54.390
Let's go ahead and create kind of a copy this one more time and we don't need any of the detail.

00:54.930 --> 01:02.490
So again, why it expanded that we don't want to expand above one so this can shrink it down.

01:02.490 --> 01:05.220
And again, feel free to copy any one of them or create another one.

01:05.220 --> 01:06.150
Doesn't really matter.

01:06.150 --> 01:08.580
We don't really keep any information inside.

01:08.580 --> 01:12.270
I just like to have the above boilerplate code, that's why.

01:12.930 --> 01:22.560
Okay, so this one is going to be information about get logged in user details really long, but it

01:22.560 --> 01:27.090
actually explicitly mentioned what this route or what this method is exactly going to do.

01:27.330 --> 01:33.060
Now this method obviously will be used only by the people who are already logged in.

01:33.060 --> 01:35.640
So the job of the middleware obviously comes in.

01:35.640 --> 01:39.240
We'll handle that into the route part, just like we have done in the past as well.

01:39.420 --> 01:42.810
So let's go ahead and say that, hey, I want to go ahead and grab a user.

01:42.810 --> 01:51.540
So we'll say user dot find command, user, dot find by ID because I can now access the idea of the

01:51.540 --> 01:51.930
user.

01:51.930 --> 01:55.290
It will be coming up directly for me to request that user again.

01:55.290 --> 01:57.300
Request that user doesn't exist.

01:57.300 --> 02:03.270
We have injected this property and we can just access a dot ID by having this one appear so really nice.

02:03.270 --> 02:07.710
I would love to hold this into available, so let's go ahead and call this one as into user.

02:07.710 --> 02:11.910
Since database is always on another continent, we stored that and that's it.

02:11.910 --> 02:13.080
That's all it takes.

02:13.080 --> 02:20.550
Now we're going to go ahead and say resort status told you really really easy that JSON and inside the

02:20.550 --> 02:29.580
JSON the classic success of true and we are also going to send the user as it is okay now anybody can

02:29.580 --> 02:34.530
actually request this route and we can actually work on with that, but we don't want anybody to access

02:34.530 --> 02:34.950
that.

02:34.950 --> 02:38.670
First, let's go ahead and use this route into the routes.

02:38.670 --> 02:41.220
So where are my routes here?

02:41.220 --> 02:42.420
Our user routes.

02:42.480 --> 02:47.640
Let's first go ahead and add this method and now let's create a route for this one.

02:47.640 --> 02:54.780
So we'll duplicate this one and we're going to call this one as simply user dashboard.

02:55.560 --> 03:00.150
Now, this can be really a simple get route since we are not sending any information, it doesn't need

03:00.150 --> 03:00.900
to be a post route.

03:00.900 --> 03:04.440
It can be a simple get route and not like that.

03:04.440 --> 03:04.930
There we go.

03:06.470 --> 03:10.130
And obviously the method that will be controlling this is going to be this one.

03:11.720 --> 03:17.210
First, this should be all okay and I should be able to visit this route because we are not predicting

03:17.210 --> 03:17.990
it right now.

03:19.820 --> 03:25.180
So let's go ahead and kind of save as and this one will be user dashboard.

03:25.190 --> 03:26.900
Let's go ahead and save this one.

03:27.140 --> 03:29.510
This is going to be a get route.

03:29.510 --> 03:30.980
So let's save this one.

03:31.400 --> 03:34.540
And the route that you'll be visiting up is user dashboard.

03:34.550 --> 03:35.960
So this should be all good.

03:36.140 --> 03:38.420
And let's go ahead and send this one.

03:38.600 --> 03:42.210
And it says, hey, I cannot read the property of undefined.

03:42.230 --> 03:45.410
So looks like something is missing.

03:45.410 --> 03:48.970
So it's not able to read the token from the cookie or something.

03:48.980 --> 03:55.570
Let's go ahead and see out what is the issue that is it says cannot read the property ID of undefined.

03:55.580 --> 03:57.860
Let's see that where we are missing this one.

03:58.070 --> 04:00.140
Oh really really my bad.

04:00.170 --> 04:02.240
Two too bad of a this of error.

04:02.270 --> 04:07.970
Now the reason why it's not able to see this ID because we haven't injected the ID, so obviously we

04:07.970 --> 04:13.250
need to inject something in this root in between so that there is something that it can work on with

04:13.250 --> 04:13.490
that.

04:13.490 --> 04:17.900
So obviously we need to bring in now our middleware and inject this middleware so that it can check

04:17.900 --> 04:20.150
in whether this ID exists or not and all of that.

04:20.150 --> 04:23.980
So without this injecting the middleware, this obviously is not going to work.

04:23.990 --> 04:25.940
So let's go ahead and import that.

04:25.940 --> 04:27.320
So this is our middleware.

04:27.320 --> 04:28.760
We are calling it as is logged in.

04:28.760 --> 04:30.560
Let's see if the auto input works.

04:30.560 --> 04:33.020
So is logged in.

04:33.020 --> 04:34.040
Yeah, really nice.

04:34.040 --> 04:34.820
I love that.

04:34.820 --> 04:36.740
So it is logged in is now working.

04:36.740 --> 04:43.670
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

04:43.670 --> 04:45.380
and let me just quickly check.

04:45.380 --> 04:48.660
This is a method itself, so we don't need to worry.

04:48.680 --> 04:53.990
Now, before the get request actually comes up onto this load and this method takes control, we're

04:53.990 --> 04:56.950
going to just paste this one, have a comma, and that's it.

04:56.960 --> 05:03.800
So now the request will first go to is logged in and we are going to verify that whether is this user

05:03.800 --> 05:08.450
is able to access this dashboard or not and then this request goes in there.

05:08.450 --> 05:10.010
So hopefully in theory, this should work.

05:10.010 --> 05:15.170
Now let's go ahead and check it one more time and we are using this user dashboard.

05:15.170 --> 05:19.700
Let's go ahead and send this one and let's see that what we are receiving in the body.

05:19.700 --> 05:26.390
So we are receiving all success, the user, the ID, secure ID, the idea of the user, name, email,

05:26.390 --> 05:28.700
roll, whatever is there, it's coming in.

05:28.850 --> 05:32.510
Most importantly, this is not all the check that we have done.

05:32.510 --> 05:33.770
Now we need to log out.

05:33.770 --> 05:40.760
So let's go ahead and send a log out and it says it is going to log in.

05:40.760 --> 05:43.250
Come on, it should be log out.

05:44.060 --> 05:45.500
Save that.

05:45.830 --> 05:47.810
Okay, now let's go ahead and log out.

05:47.840 --> 05:48.030
Okay.

05:48.080 --> 05:48.980
So log out is success.

05:48.980 --> 05:56.600
This means that now if I check into the cookies, there is there shouldn't be nothing up here because

05:56.600 --> 05:59.660
this is the t shirt store environment variable.

05:59.870 --> 06:02.720
So let's go ahead and log out one more time.

06:03.440 --> 06:05.990
And here the cookies are all going out.

06:06.670 --> 06:09.520
But this one is not yet refreshed.

06:09.520 --> 06:11.170
So I need to probably somehow.

06:11.170 --> 06:12.430
How can I refresh this?

06:12.430 --> 06:13.040
I have no idea.

06:13.060 --> 06:14.830
Let's go ahead and try to send this one.

06:15.170 --> 06:15.420
Okay.

06:15.430 --> 06:16.690
So it says no cookies yet.

06:16.690 --> 06:22.720
So this time it got refreshed and in the body it says JSON web token error JWT malformed.

06:22.720 --> 06:26.200
So here errors need to be taken care a little bit better.

06:26.200 --> 06:31.000
But again, the idea is that we should be able to do this properly a little bit better.

06:31.000 --> 06:34.270
But the whole idea is we are not receiving any of the data data.

06:34.270 --> 06:35.410
So this is all good.

06:35.410 --> 06:37.600
We are not receiving any of the token.

06:37.930 --> 06:38.320
Okay.

06:38.320 --> 06:40.840
Now, one more interesting thing that I would like to mention here.

06:40.840 --> 06:46.990
As I told you, that sometimes token might not go into the cookie itself, token might go into authorization.

06:46.990 --> 06:48.520
So let's go ahead and check out that.

06:48.520 --> 06:51.460
So in this, log in or sign up.

06:52.000 --> 06:57.640
Now, we are not having any of that, so let's go ahead and have this one as a login.

06:58.030 --> 07:01.870
Again, why are we not having anything inside the body of the login?

07:02.660 --> 07:04.100
Nothing here as well.

07:04.430 --> 07:06.380
Again, I think we are done for now.

07:06.380 --> 07:09.350
Let's go ahead and try to get the user one more time by logging in.

07:09.800 --> 07:11.390
I will go into the body roar.

07:11.420 --> 07:13.880
Jason, let's go ahead and work on with that.

07:13.970 --> 07:16.130
So this one is going to have an email.

07:17.880 --> 07:20.940
That email will be to add the date ae dot dev.

07:20.970 --> 07:22.580
This should be saved up all for me.

07:22.590 --> 07:25.020
I shouldn't be writing this all over the place.

07:26.770 --> 07:29.080
And the password is going to be one, one, two, two, three, three.

07:29.410 --> 07:31.270
And let's send this one.

07:31.360 --> 07:32.080
So there we go.

07:32.110 --> 07:36.400
Now, what I'm going to do is I'm going to go ahead and copy this token.

07:36.970 --> 07:39.520
And now I will send a log out request.

07:39.520 --> 07:40.990
So this should be all saved.

07:41.680 --> 07:43.930
And this is going to send.

07:44.980 --> 07:46.090
A log out requests.

07:46.090 --> 07:48.460
Everything is all cleared out in our user dashboard.

07:48.460 --> 07:51.290
If I go ahead and send this again, we are receiving the same errors.

07:51.310 --> 07:52.970
That is exactly what we want.

07:53.020 --> 07:58.360
But what I want to check out is inside the headers, if I can actually go ahead and send a beta token

07:58.360 --> 07:58.840
there.

07:59.260 --> 08:00.270
So there we go.

08:00.280 --> 08:05.950
I can say beta space and the token and send this one and notice that I I'm also am receiving the data.

08:05.950 --> 08:10.540
So this was a point of checking whether things are working on mobile or not because in the mobile things

08:10.540 --> 08:11.920
might not come from the cookie.

08:11.920 --> 08:16.090
It might be absolutely clean, it might come up from the authorization and the beta token.

08:16.090 --> 08:20.320
Again, you can use this authorization and can say, Hey, I want to send a beta token.

08:20.320 --> 08:22.060
This will do exactly the same thing.

08:22.060 --> 08:27.370
So just to mention that yeah, there are sometimes multiple places due to the exact same thing.

08:27.400 --> 08:29.260
It again gives you exact same thing.

08:29.860 --> 08:35.770
Okay, so this means things are working good and working fine and our Morgan is also working absolutely

08:35.770 --> 08:36.340
fine.

08:36.340 --> 08:39.400
Our errors could do a little bit better job than this one.

08:39.400 --> 08:44.920
We can actually grab this exact error that if the error type is this, then go ahead and say, hey,

08:44.920 --> 08:46.270
this is something and this is something.

08:46.270 --> 08:49.180
But again, not too much where it at this point of time.

08:49.210 --> 08:51.190
Okay, let's see what else we have to do.

08:51.460 --> 08:51.790
Okay.

08:51.850 --> 08:57.130
Now we have to work on some of the put requests that maybe user is logged in and want to update this

08:57.130 --> 09:01.180
password or update rest of the things like email, maybe something else.

09:01.180 --> 09:03.130
Let's go ahead and catch up in the next video.
