WEBVTT

00:03.730 --> 00:08.320
Hey there, everyone had a share and log out route is one of the most easiest route to work on.

00:08.320 --> 00:12.460
But first, pay it small attention here and listen to my theory.

00:12.460 --> 00:14.260
This is very important for you.

00:14.290 --> 00:18.880
Now I see a lot of people fail in the interviews because they don't focus too much on the fundamentals.

00:18.880 --> 00:23.380
Anybody can write a log out route, but people who actually know how the log out procedure is going

00:23.380 --> 00:25.840
to work, they are most important for the company.

00:25.840 --> 00:26.920
So here this out.

00:26.920 --> 00:31.660
So far we have been working with the JWT token and one thing that you should absolutely understand about

00:31.660 --> 00:33.940
the JWT token, they are stateless.

00:33.940 --> 00:37.150
They doesn't really care who you are or who you are.

00:37.150 --> 00:42.910
Not as long as anybody who is going to have this token, he can log in as long as the token is valid.

00:42.910 --> 00:44.110
Expiry is there?

00:44.110 --> 00:48.880
So there is no way that you can manually go ahead and change that expiry once the token is being sent

00:48.880 --> 00:49.360
to the user.

00:49.360 --> 00:50.560
This is not possible.

00:50.590 --> 00:55.030
The way how you have to manage it is make sure that the token is being deleted.

00:55.030 --> 00:59.110
Now this deletion happens of course from the cookies we are going to do it because we are sending it

00:59.110 --> 00:59.920
to another cookie.

00:59.920 --> 01:04.450
If you are storing these tokens into your application on the front end side, it is the responsibility

01:04.450 --> 01:10.870
of the front end developer to remove those tokens from the local storage or wherever he is storing that

01:10.870 --> 01:15.520
now again for the same reason, some people like to store these tokens into the back end and try to

01:15.520 --> 01:16.600
back and forth save it.

01:16.600 --> 01:18.690
But I think that is not an efficient way.

01:18.700 --> 01:23.650
Every single page you are receiving a call and you are calling to the database and then comparing it

01:23.650 --> 01:24.940
and sending it back the data.

01:24.940 --> 01:27.250
You are just wasting a whole lot of time for that.

01:27.250 --> 01:29.170
So make sure you just take care of these things.

01:29.170 --> 01:31.270
And that's all I have to say on this one.

01:31.390 --> 01:33.640
So let's go ahead and work on with this one.

01:33.940 --> 01:35.200
We're going to just shrink this one.

01:35.200 --> 01:37.510
And again, this is what we need.

01:37.510 --> 01:40.180
So let's go ahead and kind of a copy paste this one.

01:40.180 --> 01:42.580
We won't be using any of the code inside that.

01:42.580 --> 01:47.650
But again, it makes sense sometimes to me at least to have a boilerplate up and running.

01:47.650 --> 01:48.340
So there we go.

01:48.550 --> 01:52.780
This one is going to be simply log out, wrapping up with the big promise.

01:52.780 --> 01:54.940
That is all what we need now.

01:55.240 --> 02:00.460
So how we're going to work with that now we have stored these tokens into just one place.

02:00.460 --> 02:01.450
We need to clear them up.

02:01.450 --> 02:05.290
So resort cookie, this is all where we are storing that.

02:05.290 --> 02:09.220
So in the response we are going to say, Hey, you have a property known as token.

02:09.220 --> 02:12.460
The value of this token is going to now happen as null.

02:12.460 --> 02:14.800
That's all you have to do and you have cleared that out.

02:14.830 --> 02:18.640
Now, apart from this, we are going to also change the expiry date as well.

02:18.640 --> 02:21.430
So we're going to go ahead that this cookie has now expired.

02:21.430 --> 02:23.950
So we're going to go ahead and say expires.

02:23.950 --> 02:24.760
There we go.

02:25.540 --> 02:26.410
Yep, looks good.

02:26.440 --> 02:28.420
And this expires takes just the date.

02:28.420 --> 02:36.100
So we're going to say new date and we're going to provide a date dot by that date dot now and execute

02:36.100 --> 02:36.310
that.

02:36.310 --> 02:38.950
So immediately the existing date will pass on there.

02:39.100 --> 02:43.240
And apart from this, we need to pass on one more parameter which is going to be http.

02:43.240 --> 02:52.660
So http only and we have to pass on this as true now that I said this http correctly, I guess I have

02:52.660 --> 02:55.690
said it correctly into the helper method as well.

02:55.690 --> 03:01.210
Let me just quickly check that cookie token and yep, it is correct.

03:02.860 --> 03:03.370
Okay.

03:04.000 --> 03:05.500
So that's all what we got to do.

03:05.500 --> 03:09.910
And now once this cookie is all done, then we are going to send another response.

03:09.910 --> 03:13.990
Now we can change on this response, but this is all we are manipulating the cookie.

03:13.990 --> 03:15.460
We can send another response.

03:15.460 --> 03:21.460
So we're going to go ahead and say, hey, now the status is going to be 200 and we are going to send

03:21.460 --> 03:28.120
you a JSON response which says success is true and you have successfully logged out.

03:28.120 --> 03:36.070
So let's provide a message as well that's going to say log, log out success.

03:36.550 --> 03:38.440
Too many sees that figure.

03:38.440 --> 03:39.760
So log out success.

03:39.760 --> 03:41.770
Now, that's all it takes to log out.

03:41.770 --> 03:42.100
Totally.

03:42.100 --> 03:45.670
It's really simple in case you are storing it somewhere else, maybe in the database and something.

03:45.670 --> 03:49.360
So go ahead and figure out how you are going to remove those tokens from there as well.

03:49.630 --> 03:53.800
Now all it takes is really come up here and import this one up here.

03:53.800 --> 03:58.750
So let's go ahead and say, hey, we need to go ahead and bring in log out, let's duplicate this one

03:58.750 --> 04:00.640
and provide a simple route for that.

04:00.640 --> 04:01.390
Log out.

04:01.420 --> 04:03.430
Now, log out is not sending us anything.

04:03.430 --> 04:04.990
So it can be a simple get request.

04:04.990 --> 04:09.460
And the guy who is who will be handling this is going to be simply a log out.

04:09.490 --> 04:10.450
Told you that.

04:10.450 --> 04:11.080
Simple.

04:11.110 --> 04:12.670
Now it's time to test this out.

04:12.670 --> 04:16.060
So let's go ahead and move on to the postman and test this one out.

04:16.150 --> 04:19.300
So we're going to go ahead and make a copy of this one.

04:19.300 --> 04:24.700
We're going to call this one as log out and this one is going to be saved.

04:24.700 --> 04:25.870
Yeah, same place.

04:26.200 --> 04:29.020
Now, let's go ahead and change this one into a get request.

04:29.020 --> 04:32.680
Save that and the domain is going to change to log out.

04:32.680 --> 04:38.140
And in case you can remember that we got the cookies up here, this should be cleared out as soon as

04:38.140 --> 04:39.070
I make a get request.

04:39.070 --> 04:40.990
We don't need to send send any parameter.

04:40.990 --> 04:42.610
Let's send that and then we go.

04:42.640 --> 04:44.020
Cookies are cleared in the body.

04:44.020 --> 04:45.400
We got the response of success.

04:45.400 --> 04:45.900
True.

04:45.940 --> 04:46.280
Log out.

04:46.300 --> 04:47.260
Success totally.

04:47.260 --> 04:50.020
From now here onwards, the things are actually really simple.

04:50.020 --> 04:51.610
Not because they are simple.

04:51.610 --> 04:55.960
Because we have worked so hard in the entirety of the course that things are actually looking like a

04:55.960 --> 04:56.530
breeze.

04:56.530 --> 04:58.090
So that is very important.

04:58.090 --> 05:00.010
Let's go ahead and catch up in the next video.
