1
00:00:08,189 --> 00:00:09,330
In this video.

2
00:00:09,330 --> 00:00:13,530
Let's see how we can implement logging out a user.

3
00:00:13,830 --> 00:00:15,810
So let's look at the process.

4
00:00:15,840 --> 00:00:23,680
Logging out a user simply means that we are going to remove the user from the cookie, and that is all.

5
00:00:23,700 --> 00:00:28,380
So if I log in as Lily here, that is Lizzie.

6
00:00:28,920 --> 00:00:31,020
And the password is this one.

7
00:00:31,020 --> 00:00:38,250
When I hit send, you can see that I have the profile page and if I check the cookies, you will see

8
00:00:38,250 --> 00:00:42,360
that I have the details about the user.

9
00:00:42,660 --> 00:00:51,150
So the whole logic is that when I click on the log out, I won't remove the details from the cookies

10
00:00:51,150 --> 00:00:53,430
and that's what we are going to do.

11
00:00:53,460 --> 00:00:55,450
So how can we get that one done?

12
00:00:55,470 --> 00:00:57,720
It's pretty simple with EXPRESS.

13
00:00:57,930 --> 00:01:04,190
So I'm going to create a route where we are going to click on this button to initiate that route.

14
00:01:04,200 --> 00:01:09,090
So here before or after, log in, let's do it after log in.

15
00:01:09,120 --> 00:01:18,240
Here is going to be the log out and let's create the route app dot get and here are going to be the

16
00:01:18,270 --> 00:01:23,550
log out and and the arrow function.

17
00:01:23,970 --> 00:01:30,360
And here what we are going to do is we need to delete the cookies.

18
00:01:30,360 --> 00:01:32,180
So how are we going to do it?

19
00:01:32,190 --> 00:01:34,560
Well, it's pretty simple with express.

20
00:01:34,560 --> 00:01:39,180
So on the response, we have a method called Cookie.

21
00:01:39,390 --> 00:01:43,470
And for this one we pass in the property that you want to remove.

22
00:01:43,470 --> 00:01:49,200
In one case we want to remove the username, or if we want to remove everything, we are going to pass

23
00:01:49,200 --> 00:01:51,510
in full name, user name and name.

24
00:01:51,510 --> 00:01:53,280
So here we go.

25
00:01:53,610 --> 00:01:56,100
All right, so we pass in full name here.

26
00:01:56,100 --> 00:02:03,690
I want to remove name and copy this one and I also want to remove the username.

27
00:02:03,690 --> 00:02:06,600
And lastly, I also want to remove the name.

28
00:02:06,600 --> 00:02:15,030
I think this name is not from us from database, I think it is from this one and the one that we set.

29
00:02:15,030 --> 00:02:16,290
So don't worry about the name.

30
00:02:16,290 --> 00:02:17,820
So let's remove the name by right.

31
00:02:17,820 --> 00:02:19,980
Click in and click on that.

32
00:02:20,070 --> 00:02:28,410
So back here now let's go to the log out before the cookie will be set unless we return something from

33
00:02:28,410 --> 00:02:29,190
the root.

34
00:02:29,190 --> 00:02:37,200
So here address, dot redirect and after deleting, let's go to the log in page.

35
00:02:37,320 --> 00:02:38,250
I'll start.

36
00:02:38,250 --> 00:02:40,110
So moment of truth.

37
00:02:40,140 --> 00:02:48,330
So when I click on Look Out, you can see that I have removed the cookies and again I can log in again

38
00:02:48,330 --> 00:02:52,290
with Lizzy and one, two, three, four, five and hit send.

39
00:02:52,290 --> 00:02:58,050
Now I have the name here but I see undefined for the username.

40
00:02:58,170 --> 00:03:00,420
What is the problem?

41
00:03:00,930 --> 00:03:03,720
Maybe for logging in.

42
00:03:03,900 --> 00:03:07,650
I am not sending or pass in the right details.

43
00:03:07,680 --> 00:03:08,460
Oh sorry.

44
00:03:08,490 --> 00:03:12,480
Supposed to be user found but not user found name.

45
00:03:12,720 --> 00:03:13,290
Yes.

46
00:03:13,290 --> 00:03:16,110
So again, let's look out now.

47
00:03:16,110 --> 00:03:17,190
I have removed that.

48
00:03:17,190 --> 00:03:19,470
So let's log in back again.

49
00:03:20,680 --> 00:03:28,540
And hit send log in and now we have the log in again as quantified well.

50
00:03:28,990 --> 00:03:33,730
Oh sorry user found dot full name the user name.

51
00:03:33,740 --> 00:03:34,900
Sorry guys.

52
00:03:34,900 --> 00:03:36,220
Bottom side.

53
00:03:36,430 --> 00:03:37,050
All right.

54
00:03:37,060 --> 00:03:44,560
So again, let's look out and then let's log in again, Lizzie and one, two, three, four, five and

55
00:03:44,560 --> 00:03:45,490
hit log in.

56
00:03:45,640 --> 00:03:47,880
And now we have the right details.

57
00:03:47,890 --> 00:03:49,560
So if I go to protected.

58
00:03:49,600 --> 00:03:50,020
Yes.

59
00:03:50,020 --> 00:03:56,740
Where I come by, as soon as I go to the profile, there is no key or maybe button to go there unless

60
00:03:56,740 --> 00:04:01,720
I log in again before I can go to my profile like that.

61
00:04:01,720 --> 00:04:05,500
And as that when I click look out, I remove that.

62
00:04:05,500 --> 00:04:11,410
If I go to protect it, you are not log in now everything is correct.

63
00:04:11,560 --> 00:04:17,800
So in the next video, let's talk about session based authentication, meaning we are going to improve

64
00:04:17,800 --> 00:04:21,279
the way we implemented cookie based authentication.

