1
00:00:08,180 --> 00:00:09,230
Welcome back.

2
00:00:09,260 --> 00:00:13,700
In this video, let's see how we can implement login out.

3
00:00:13,700 --> 00:00:17,540
And it's very simple with experts.

4
00:00:17,540 --> 00:00:19,820
So back to our code.

5
00:00:19,850 --> 00:00:24,110
Let me collapse the terminal here and let's remove this.

6
00:00:24,110 --> 00:00:32,090
Once the next step is let's implement the logout functionality, we can bring it any way we want.

7
00:00:32,090 --> 00:00:43,280
So let's bring it here as log out and here is the handler app dot get and slash look out.

8
00:00:44,750 --> 00:00:52,480
Log out and then as always, our callback function, req and response and there you go.

9
00:00:52,490 --> 00:00:54,560
So how are we going to look out?

10
00:00:54,740 --> 00:00:58,820
We can look out on the rec dot session.

11
00:00:58,970 --> 00:01:01,970
We have a method called destroy.

12
00:01:01,970 --> 00:01:04,430
So let's try out first and see.

13
00:01:04,430 --> 00:01:12,800
Let's come down here and then let's redirect the user to the log in page after logging out.

14
00:01:12,800 --> 00:01:15,650
So let's see how we are going to achieve this one.

15
00:01:15,650 --> 00:01:19,370
Well, so back to the template of the profile.

16
00:01:19,370 --> 00:01:22,070
That's where we have the log out.

17
00:01:22,070 --> 00:01:25,280
So let's look in as lazy.

18
00:01:25,280 --> 00:01:28,130
One, two, three, four, five and log in.

19
00:01:28,130 --> 00:01:34,460
And now on this button, when I click on that, I want to delete the session and I believe we have that

20
00:01:34,460 --> 00:01:39,080
one already where we implemented the cookie based functionality.

21
00:01:39,410 --> 00:01:41,570
I think, yeah, it's here.

22
00:01:41,570 --> 00:01:44,270
So this one is for the cookie based one.

23
00:01:44,270 --> 00:01:45,620
So let me comment one.

24
00:01:45,620 --> 00:01:51,830
And now let's take to the session one, which is this functionality.

25
00:01:51,830 --> 00:01:55,250
So now let's go ahead and then click on that.

26
00:01:55,250 --> 00:01:59,420
So let's refresh it now because I've refreshed my server.

27
00:01:59,420 --> 00:02:00,650
That's why I got that.

28
00:02:00,650 --> 00:02:02,360
So let's log in again.

29
00:02:05,080 --> 00:02:09,550
And let's look out and you can see that everything is working.

30
00:02:09,699 --> 00:02:16,270
Now, if I go to protected and you can see that the unauthorized template has been rendered, meaning

31
00:02:16,270 --> 00:02:18,180
that I have locked out.

32
00:02:18,190 --> 00:02:23,540
So this is how we can lock out a user that is our sun.

33
00:02:23,560 --> 00:02:30,700
So again, as soon as I refresh the server, you can see that the session destroyed.

34
00:02:30,910 --> 00:02:31,760
Do you remember?

35
00:02:31,780 --> 00:02:32,200
Yes.

36
00:02:32,200 --> 00:02:37,900
So let me prove to you one more time, then we get back into how we are going to avoid that.

37
00:02:38,050 --> 00:02:45,970
So here let's console.log the rec dot session and I believe for this one we have done it before.

38
00:02:46,180 --> 00:02:56,290
So if I open the terminal and now if I go to home page and let's go to homepage and refresh now and

39
00:02:56,290 --> 00:02:56,910
check it out.

40
00:02:56,920 --> 00:03:05,470
You can see that on this session there is no log in user, but as soon as I log in with this user.

41
00:03:07,090 --> 00:03:08,400
You can see that.

42
00:03:08,410 --> 00:03:15,760
And then you go to homepage and now you see that I have the user as soon as I restart the server.

43
00:03:16,390 --> 00:03:19,840
Yes, let's go and I go to homepage.

44
00:03:19,840 --> 00:03:21,010
Let's refresh it.

45
00:03:21,010 --> 00:03:24,580
And now we see that there is no log in user.

46
00:03:24,760 --> 00:03:32,980
This is a reason why we say that HTTP servers are stateless, so it is our responsibility to keep the

47
00:03:32,980 --> 00:03:34,720
search engine in a state.

48
00:03:34,930 --> 00:03:42,700
And then this video we are going to implement how we can save the session inside MongoDB.

49
00:03:42,730 --> 00:03:50,080
So any time we want to visit, whether our server shut down or we look out, we still have the user

50
00:03:50,080 --> 00:03:51,910
inside our database.

51
00:03:51,910 --> 00:03:54,640
So let's get into that in the next video.

