1
00:00:00,660 --> 00:00:06,740
In this video, we are going to implement the lockout functionality.

2
00:00:06,750 --> 00:00:08,970
So let's look at the flow.

3
00:00:09,630 --> 00:00:15,360
A user is being locked out when we delete the user from session.

4
00:00:15,360 --> 00:00:21,720
Remember, as soon as a user is logged in, we are putting the user into session.

5
00:00:21,720 --> 00:00:29,550
So all what we are going to do is to destroy or remove the user from the session and that is lockout.

6
00:00:29,640 --> 00:00:34,350
So let's get into the controllers and users and users.

7
00:00:34,650 --> 00:00:43,830
Jess And this is a controller for logging out and assistant right now is just sending this data back

8
00:00:43,830 --> 00:00:47,730
to the user when we hit this controller or endpoint.

9
00:00:48,240 --> 00:00:51,330
So how are we going to destroy this session?

10
00:00:51,330 --> 00:00:55,110
So let me add a comment by saying destroy.

11
00:00:57,010 --> 00:00:58,120
Session.

12
00:00:58,120 --> 00:01:01,960
And for this, we are not going to handle the promise.

13
00:01:01,960 --> 00:01:03,790
So let me remove the catch.

14
00:01:03,790 --> 00:01:05,890
BLOCK So here we go.

15
00:01:06,010 --> 00:01:12,910
On the rec, we have the session property and we have a method called destroyed.

16
00:01:14,350 --> 00:01:17,230
And then you pass in a callback function.

17
00:01:17,230 --> 00:01:25,870
And in here we are going to redirect the user after logging out as red dot redirect.

18
00:01:26,260 --> 00:01:35,560
Then we will redirect the user back to the log in endpoint, and that is API version one users.

19
00:01:36,190 --> 00:01:37,230
For West Lash.

20
00:01:37,240 --> 00:01:38,260
Look in.

21
00:01:38,830 --> 00:01:44,500
Next step is let's make a request to make sure that this controller is being called.

22
00:01:44,650 --> 00:01:47,890
So let's get back to the user's route.

23
00:01:47,890 --> 00:01:49,480
And here we go.

24
00:01:50,110 --> 00:01:54,850
If we scroll down, we have the root for logging out.

25
00:01:54,880 --> 00:01:59,230
So let's go ahead and then make the request from the back end.

26
00:02:00,070 --> 00:02:03,400
And this is a URL and then the method.

27
00:02:03,400 --> 00:02:10,240
So when I hit send, you can see that we got this message simply means that our controller is not being

28
00:02:10,240 --> 00:02:16,450
called, but instead it called different routes and that is the user details.

29
00:02:16,810 --> 00:02:23,620
Like I said, express routing always check the matching route, so this one will call before this.

30
00:02:23,620 --> 00:02:28,100
So let me bring this one before the IDs.

31
00:02:28,120 --> 00:02:29,050
All right.

32
00:02:29,050 --> 00:02:38,620
So now if I hit send and you can see that it has redirected the user to log in, and this is a log in

33
00:02:38,620 --> 00:02:39,580
templates.

34
00:02:39,730 --> 00:02:40,690
All right.

35
00:02:40,690 --> 00:02:44,890
So let's go ahead and make the request from the client side.

36
00:02:45,070 --> 00:02:50,380
So where we want to trigger the endpoint is the log out link here.

37
00:02:50,410 --> 00:02:58,540
So let's look at the number templates, views, partials, and then the number.

38
00:02:58,750 --> 00:03:01,600
So this is a link for logging out.

39
00:03:01,600 --> 00:03:09,250
So we are going to pass in the endpoint, going to be forward slash API, forward slash version one

40
00:03:09,280 --> 00:03:12,190
users and log out.

41
00:03:13,280 --> 00:03:14,110
All right.

42
00:03:14,120 --> 00:03:17,300
The next step is let's hit look out.

43
00:03:17,720 --> 00:03:19,970
And you can see that it worked.

44
00:03:20,060 --> 00:03:27,440
And if I look back as Ben at gmail.com, One, two, three, four, five.

45
00:03:27,470 --> 00:03:28,520
Look in.

46
00:03:29,270 --> 00:03:31,140
And look out.

47
00:03:31,160 --> 00:03:32,150
Perfect.

