1
00:00:07,610 --> 00:00:08,360
All right.

2
00:00:08,390 --> 00:00:12,830
Let's get started with cookie based authentication.

3
00:00:13,250 --> 00:00:20,750
Well, we are going to use the previous project, but for me, I have made a copy and then rename this

4
00:00:20,750 --> 00:00:24,110
one to cookie based authentication.

5
00:00:24,350 --> 00:00:30,550
So in that way, in the future, I can make reference to those different types of authentication.

6
00:00:30,560 --> 00:00:32,450
So let's get started.

7
00:00:32,600 --> 00:00:40,490
Well, we can maintain this route or we can remove everything from this route, but for the meantime,

8
00:00:40,490 --> 00:00:43,300
let's maintain it for future references.

9
00:00:43,310 --> 00:00:51,440
So let's collapse the route that we are not going to work on at the moment and have some enough room

10
00:00:51,440 --> 00:00:53,460
to start with cookies.

11
00:00:53,480 --> 00:00:55,700
So now down here or up.

12
00:00:55,700 --> 00:00:57,350
Let's start from the up here.

13
00:00:57,770 --> 00:00:58,430
Okay.

14
00:00:58,460 --> 00:00:59,940
Up here.

15
00:00:59,960 --> 00:01:00,890
Yes.

16
00:01:01,310 --> 00:01:03,370
Let me collapse this one also.

17
00:01:03,380 --> 00:01:06,640
And now let's start with good.

18
00:01:06,650 --> 00:01:14,630
So the whole logic is that we are going to save the user login details inside the cookie and the cookie

19
00:01:14,630 --> 00:01:18,470
I will save inside the user browser go.

20
00:01:18,470 --> 00:01:20,430
So how can we create that?

21
00:01:20,450 --> 00:01:22,340
So let's create one route.

22
00:01:22,340 --> 00:01:26,210
Where is going to send a cookie to the browser?

23
00:01:26,240 --> 00:01:31,890
In that way we are able to use that one for logging and logging out.

24
00:01:31,910 --> 00:01:34,700
So the first route going to be sent.

25
00:01:35,680 --> 00:01:36,540
Cookie.

26
00:01:37,030 --> 00:01:47,230
To the client and that is a browser so app darts gates and the endpoint it can be anything but let's

27
00:01:47,230 --> 00:01:48,730
make it more descriptive.

28
00:01:48,730 --> 00:02:00,730
I send cookies and our callback function as that I have access to req and then my response.

29
00:02:00,730 --> 00:02:04,720
So it is how we send cookie as easy as you think.

30
00:02:04,720 --> 00:02:06,820
So here send cookie.

31
00:02:08,090 --> 00:02:11,270
Go make a list of response on that.

32
00:02:11,270 --> 00:02:19,730
We have a method called Cookie and this is a method that takes in two elements that is the key value

33
00:02:19,730 --> 00:02:20,300
per.

34
00:02:20,300 --> 00:02:23,000
So here we can save any property.

35
00:02:23,000 --> 00:02:30,980
For the meantime, let's make the property name as name and the value is going to be John as that.

36
00:02:30,980 --> 00:02:38,990
So with this one, let's go ahead and send a response that cookie sent as that.

37
00:02:40,380 --> 00:02:41,710
Cookie set.

38
00:02:42,230 --> 00:02:43,320
I was sent.

39
00:02:44,250 --> 00:02:45,600
I said, whatever.

40
00:02:45,990 --> 00:02:47,490
So now I have save it.

41
00:02:47,520 --> 00:02:53,400
Now let's go to the browser and let's make use of forest slash cookies.

42
00:02:55,050 --> 00:02:56,490
And as called sense.

43
00:02:56,490 --> 00:02:58,290
Let's hit enter now.

44
00:02:58,290 --> 00:03:00,420
I think my endpoint is wrong.

45
00:03:00,420 --> 00:03:01,830
It's send cookies.

46
00:03:02,880 --> 00:03:04,090
I made a mistake here.

47
00:03:04,090 --> 00:03:06,540
You're going to be saying cookies.

48
00:03:06,540 --> 00:03:09,090
Now I got a message that cookie sent.

49
00:03:09,090 --> 00:03:16,650
So how can we check right click and click on inspect and then click on the application.

50
00:03:16,830 --> 00:03:22,590
And here on the left side here and a storage click on cookies.

51
00:03:22,590 --> 00:03:27,900
And in there we have our URL which is lookup with column 3000.

52
00:03:27,990 --> 00:03:35,790
If you click on that, you can see that we have this window with a name and value and this is where

53
00:03:35,790 --> 00:03:38,430
our cookies are being stored.

54
00:03:38,430 --> 00:03:44,250
So the name represents the name of the cookie we set, which is name here.

55
00:03:44,400 --> 00:03:48,060
And the value is John, which is this one.

56
00:03:48,240 --> 00:03:53,820
And we have additional property, the domain that it is on which is local.

57
00:03:53,880 --> 00:04:02,250
Host indeed it is local host and a path and also have a session called expire, meaning at what time

58
00:04:02,250 --> 00:04:04,260
we want to expire this cookie.

59
00:04:04,260 --> 00:04:10,320
And I'll explain to you very soon and you also have some property called HTTP only.

60
00:04:10,320 --> 00:04:16,410
It means that if you don't want anybody to tamper with our cookies, we need to send the cookie over

61
00:04:16,410 --> 00:04:17,760
at https.

62
00:04:17,760 --> 00:04:19,680
So I will show you as you move on.

63
00:04:19,680 --> 00:04:24,360
For the meantime, let's focus on this two key value per.

64
00:04:24,570 --> 00:04:31,680
And since we have the user in the browser upon every request, our server can check if there's a user

65
00:04:31,680 --> 00:04:37,890
name inside the browser so that the flow of cookie based authentication.

66
00:04:37,890 --> 00:04:43,710
So how can we register from the form and save the data inside cookie here?

67
00:04:43,710 --> 00:04:45,330
So let me show you how we're going to do it.

68
00:04:45,330 --> 00:04:46,320
Pretty simple, right?

69
00:04:46,320 --> 00:04:47,340
Yes, it is.

70
00:04:52,600 --> 00:04:59,170
So all what we are going to do is that inside the registration route for this one.

71
00:04:59,170 --> 00:05:05,170
For the meantime, if you are trying to hash the user password before saving it, you are going to have

72
00:05:05,170 --> 00:05:05,980
a couple of steps.

73
00:05:05,980 --> 00:05:07,480
But let's make it pretty simple.

74
00:05:07,480 --> 00:05:14,530
So instead we are not going to make use of decrypt inside this or we can use it for the meantime.

75
00:05:14,530 --> 00:05:17,230
Let's ignore the big functionality.

76
00:05:17,230 --> 00:05:25,120
So let's remove that and let's also comment this one out from here or we can remove it as that.

77
00:05:25,120 --> 00:05:29,320
So now before saving, what are we going to do?

78
00:05:29,440 --> 00:05:34,810
So what comes back from the user here is a user being registered.

79
00:05:34,810 --> 00:05:40,120
So here we can assign the user into a variable as that.

80
00:05:40,120 --> 00:05:46,330
So after we got the user, then we can save the user details inside cookies.

81
00:05:46,330 --> 00:05:48,640
So here save.

82
00:05:50,670 --> 00:05:51,750
Or store.

83
00:05:53,550 --> 00:05:54,750
Username.

84
00:05:55,460 --> 00:05:57,440
And password.

85
00:05:58,250 --> 00:06:00,590
Inside the cookies.

86
00:06:00,710 --> 00:06:07,790
But to increase the security level, it is not advisable to save the password inside cookies.

87
00:06:07,790 --> 00:06:11,270
But for the meantime, let's go by this as we move on.

88
00:06:11,270 --> 00:06:13,520
We need to improve the code a little bit.

89
00:06:13,520 --> 00:06:14,990
So here we go.

90
00:06:15,020 --> 00:06:25,940
So on red dot cookie, as we did before, the property name here is going to be as that's going to be

91
00:06:25,940 --> 00:06:28,130
a string as user name.

92
00:06:28,130 --> 00:06:37,400
It can be anything but the value is going to be user from our DB and going to be the user name as that.

93
00:06:37,400 --> 00:06:43,790
And for this one, we can save many cookies as we want, so we can copy this one also.

94
00:06:43,970 --> 00:06:52,130
And down here, let's say the password for now, and we avoid that one very soon and the password from

95
00:06:52,130 --> 00:06:52,970
the DB.

96
00:06:53,000 --> 00:06:59,780
Also, I want to show you that open registration, we are going to save the user inside our cookie.

97
00:06:59,780 --> 00:07:01,010
That's what I'm trying to do.

98
00:07:01,010 --> 00:07:04,820
So now moment of truth where we also have full name.

99
00:07:04,820 --> 00:07:05,450
Why not?

100
00:07:05,480 --> 00:07:07,190
We can also save the full name.

101
00:07:07,190 --> 00:07:16,250
Also inside that we're going to be the full name and you're going to be asked to name.

102
00:07:17,730 --> 00:07:20,940
All right, so now let's go ahead and register.

103
00:07:20,970 --> 00:07:22,230
So save it.

104
00:07:22,230 --> 00:07:30,570
And now full name going to be as John Doe and username going to be as John and password.

105
00:07:30,570 --> 00:07:32,010
One, two, three, four, five.

106
00:07:32,010 --> 00:07:33,750
And let's hit register.

107
00:07:34,140 --> 00:07:39,450
Well, for some reasons we are not getting the registered user.

108
00:07:39,450 --> 00:07:40,920
Why is it so?

109
00:07:41,850 --> 00:07:47,820
All right, so let's check our code a little bit and see where we are getting something wrong, where

110
00:07:47,820 --> 00:07:49,560
isn't being saved in here.

111
00:07:49,740 --> 00:07:57,030
So let's go ahead and then console log the registered user and see if we are going to register the user.

112
00:07:57,030 --> 00:07:58,440
Well, all right.

113
00:07:58,440 --> 00:07:59,890
So here we go.

114
00:08:00,270 --> 00:08:08,070
Let's open the terminal here and check if when I see the registered user where our server has hung out

115
00:08:08,070 --> 00:08:12,000
because we are not returning anything from the root.

116
00:08:12,000 --> 00:08:18,630
So register anything here, anything here, anything here and let's see, let's check it.

117
00:08:18,630 --> 00:08:20,820
Well, we have it here.

118
00:08:21,270 --> 00:08:24,870
Let's try to put in a string here and says.

119
00:08:26,130 --> 00:08:26,790
Emma.

120
00:08:27,030 --> 00:08:29,520
Let's save it and check it out.

121
00:08:29,550 --> 00:08:30,870
Inside the browser.

122
00:08:30,900 --> 00:08:33,299
Let's go ahead and register a user.

123
00:08:33,480 --> 00:08:38,909
And at the end, we want to save the user details inside the cookie.

124
00:08:39,179 --> 00:08:45,870
So let's say we want to register Daniel, and the user name is done and the password is one, two,

125
00:08:45,900 --> 00:08:48,810
three, four, five and register.

126
00:08:48,840 --> 00:08:52,470
Well, why is it that we are not seeing the details here?

127
00:08:52,500 --> 00:08:56,880
The reason is that we are not returning anything from this root.

128
00:08:56,880 --> 00:09:07,700
So let's go ahead and retain, let's say restart, redirect and then go to the login page after registration.

129
00:09:07,710 --> 00:09:09,270
So let's save it.

130
00:09:09,270 --> 00:09:14,390
And now let's refresh the page and let's make the request.

131
00:09:14,400 --> 00:09:24,000
Let's go to register and going to be Daniel and Dan lowercase Dan and password.

132
00:09:24,000 --> 00:09:25,860
One, two, three, four, five.

133
00:09:25,860 --> 00:09:33,600
Now let's hit register and you can see something incredible has happened here we have the full name,

134
00:09:33,600 --> 00:09:40,170
which is Daniel here, and then we have the password, which is this, and we have the user name, which

135
00:09:40,170 --> 00:09:41,160
is this.

136
00:09:41,160 --> 00:09:43,480
I use imama y.

137
00:09:43,930 --> 00:09:45,210
Okay, that's okay.

138
00:09:45,360 --> 00:09:46,010
Don't worry.

139
00:09:46,020 --> 00:09:51,570
So the good news is that we are able to get the details here.

140
00:09:51,600 --> 00:09:53,360
That is awesome.

141
00:09:53,370 --> 00:09:59,000
So how can we get this data inside our root?

142
00:09:59,010 --> 00:10:06,860
But the cool thing is that for cookies like this one, we can tamper with the values here.

143
00:10:06,870 --> 00:10:11,610
So for this one, I can change this one to anything.

144
00:10:12,240 --> 00:10:20,790
You see how I'm trying to turn with the cookies and then I can even use JavaScript to access the cookies.

145
00:10:20,790 --> 00:10:30,090
So if I go to console and I make use of document dot cookie, you can see that we have the user details

146
00:10:30,090 --> 00:10:34,970
here, meaning I can use JavaScript to interact with my cookie in this way.

147
00:10:34,980 --> 00:10:42,990
That's why we say that cookies are not secured, but we will find a way to avoid this one very soon.

148
00:10:43,200 --> 00:10:47,670
Now here comes the question How can we log in?

149
00:10:47,700 --> 00:10:49,410
It's pretty simple.

150
00:10:49,620 --> 00:10:55,680
We are going to use the form to log in with our username and password.

151
00:10:55,860 --> 00:11:03,020
And since this user has been saved into our DB, we can use that one to find the user.

152
00:11:03,030 --> 00:11:07,710
If you check our database and I refresh it, you're going to see that.

153
00:11:07,710 --> 00:11:11,790
I'm going to see Daniel, which is this one over here.

154
00:11:11,820 --> 00:11:15,840
I have the username as that in full name as that.

155
00:11:15,840 --> 00:11:18,870
So how are we going to log in?

156
00:11:18,900 --> 00:11:28,200
It means that this logic remains the same for logging in, but in this one we are making use of what's

157
00:11:28,200 --> 00:11:30,090
the secret password?

158
00:11:30,090 --> 00:11:32,550
So we are going to tamper with it.

159
00:11:32,700 --> 00:11:40,380
But instead let's go ahead and register a user with hash password as we did before.

160
00:11:40,560 --> 00:11:45,600
So we are going to bring in the big package to do the registration.

161
00:11:45,600 --> 00:11:51,510
But instead upon registration, we are not going to save the password into cookies.

162
00:11:51,510 --> 00:11:54,120
So let me remove the password here.

163
00:11:54,420 --> 00:11:56,520
But for the meantime, let's maintain it.

164
00:11:56,520 --> 00:11:59,820
And now let's go ahead and then hash the user password.

165
00:11:59,820 --> 00:12:02,310
So as we did before, let's move first.

166
00:12:02,310 --> 00:12:15,960
Here we have the sorts equal to await, then be encrypt dot gen sorts, pass in ten and cast the hashed.

167
00:12:17,040 --> 00:12:23,190
Password as passed is equal to the awaits be scraped.

168
00:12:24,830 --> 00:12:25,670
Darts.

169
00:12:26,720 --> 00:12:32,150
Hash and our patch in the plane password and then the salt.

170
00:12:32,390 --> 00:12:41,660
So here before saving it, let's bring this one up, the sorting here before saving it as that.

171
00:12:41,780 --> 00:12:48,290
And now instead of this plain password, we are going to save the hash password as that.

172
00:12:48,290 --> 00:12:51,140
Now the registration is complete.

173
00:12:51,290 --> 00:12:57,620
So let's go ahead and register a new user and to check if the hash password will be saved inside the

174
00:12:57,620 --> 00:12:57,970
cookies.

175
00:12:57,980 --> 00:13:00,110
So go to register.

176
00:13:00,140 --> 00:13:01,360
Let's refresh it.

177
00:13:01,370 --> 00:13:03,940
Open the application and the cookies.

178
00:13:03,950 --> 00:13:08,720
Let's remove everything from here, trash it and let's go.

179
00:13:08,900 --> 00:13:11,450
So let's go ahead and register this time around.

180
00:13:11,450 --> 00:13:15,440
Let's say three months and four months.

181
00:13:16,660 --> 00:13:17,350
Password.

182
00:13:17,350 --> 00:13:18,910
One, two, three, four, five.

183
00:13:19,000 --> 00:13:22,540
So let's go ahead and click register and let's see.

184
00:13:22,540 --> 00:13:26,650
And indeed we have the user details inside our cookies.

185
00:13:26,680 --> 00:13:34,720
We have the full name, a famous password, a string of characters as that, and the user name Y Emma

186
00:13:34,750 --> 00:13:35,170
here.

187
00:13:35,200 --> 00:13:37,150
But we use them as well.

188
00:13:37,150 --> 00:13:37,930
Let's see.

189
00:13:38,140 --> 00:13:40,390
Well, it's because of this code.

190
00:13:40,390 --> 00:13:42,190
We are setting the username here.

191
00:13:42,190 --> 00:13:45,310
So let's remove that and use the.

192
00:13:46,460 --> 00:13:49,400
User dot username.

193
00:13:49,430 --> 00:13:49,920
Good.

194
00:13:49,940 --> 00:13:51,160
So now we have it.

195
00:13:51,170 --> 00:13:54,290
So let's go ahead and then log in.

196
00:13:54,290 --> 00:13:59,810
Now everything is correct, so let's go ahead and then log in with those credentials.

197
00:14:00,020 --> 00:14:02,310
And one, two, three, four, five.

198
00:14:02,330 --> 00:14:03,080
Let's see.

199
00:14:03,810 --> 00:14:05,990
Now everything is correct.

200
00:14:06,000 --> 00:14:07,400
So while cookies are.

201
00:14:07,620 --> 00:14:09,810
Why are we saving this user here?

202
00:14:10,080 --> 00:14:12,510
So now here comes the question.

203
00:14:12,510 --> 00:14:15,690
How can we implement the protected route?

204
00:14:15,720 --> 00:14:16,770
Remember?

205
00:14:16,770 --> 00:14:22,950
And the fact about cookies we made mention that cookies are used for session management.

206
00:14:22,980 --> 00:14:29,430
And last point is that we can use cookies to store the current user in that way.

207
00:14:29,460 --> 00:14:34,010
Upon every request, we are going to check if a user is logged in.

208
00:14:34,020 --> 00:14:36,020
So how are we going to do that?

209
00:14:36,030 --> 00:14:39,210
So back to a route called protected.

210
00:14:39,210 --> 00:14:44,040
This route here you can see that we are just sending the template.

211
00:14:44,040 --> 00:14:52,290
So here we are going to check if a user is logged in and we can do that by checking the user inside

212
00:14:52,290 --> 00:14:53,670
our browser here.

213
00:14:53,820 --> 00:15:01,380
And that way we'll be able to know if indeed there is a user cohort, Emmanuelle or Thomas or whatever.

214
00:15:01,380 --> 00:15:09,060
But before you move on, you can see that we have additional cookies here and this one is from the URL

215
00:15:09,060 --> 00:15:10,880
of the image we use.

216
00:15:10,890 --> 00:15:18,300
And like I said, that most applications use cookies to keep track about the user activity.

217
00:15:18,420 --> 00:15:23,460
So Pixabay also used what is called cookies to keep track of the user.

218
00:15:23,530 --> 00:15:25,260
We see that a domain is from where?

219
00:15:25,260 --> 00:15:33,180
From Pixabay.com because inside our model we use the URL from Pixabay.

220
00:15:33,210 --> 00:15:35,420
That's why we got cookies from Pixabay.

221
00:15:35,430 --> 00:15:38,640
For now, let's focus our own cookies here.

222
00:15:38,730 --> 00:15:40,230
So here is a clue.

223
00:15:40,260 --> 00:15:47,400
When I go to this route first I want to check if there's a user called Thomas in the cookies.

224
00:15:47,400 --> 00:15:49,080
So how can we get it?

225
00:15:49,080 --> 00:15:55,410
And to get a quick is is pretty simple using express so let's see how we can get a cookie.

226
00:15:55,410 --> 00:16:02,130
So back to the protected route here, let's try to make use of this method.

227
00:16:02,130 --> 00:16:04,920
So here let's say get cookies.

228
00:16:05,400 --> 00:16:06,480
So here we go.

229
00:16:08,580 --> 00:16:10,700
All right, so let's check it out.

230
00:16:10,710 --> 00:16:15,180
If I go to the protected route, when I click on that, let's check the console.

231
00:16:15,270 --> 00:16:18,480
You see that we have undefined.

232
00:16:18,600 --> 00:16:28,500
So by default Express cannot pass the cookies from our browser unless we installed a third package called

233
00:16:28,500 --> 00:16:29,190
Cookie Pass.

234
00:16:29,610 --> 00:16:36,810
So and at this point we say that we need a package called Cookie Pass to send back the cookie to the

235
00:16:36,810 --> 00:16:39,060
server upon each request.

236
00:16:39,060 --> 00:16:45,520
So back to our terminal, let's go ahead and install a package called cookie parser.

237
00:16:45,810 --> 00:16:49,680
So npm I cookie.

238
00:16:50,310 --> 00:16:51,770
Dash Plaza.

239
00:16:52,260 --> 00:16:55,310
And here we go.

240
00:16:55,320 --> 00:16:58,000
Now it has finished installing.

241
00:16:58,020 --> 00:16:58,830
Boom.

242
00:16:59,160 --> 00:17:03,480
Okay, let's clear the console and let's start this server.

243
00:17:03,570 --> 00:17:06,720
Now, how can we configure cookie parser?

244
00:17:07,050 --> 00:17:08,160
It's really simple.

245
00:17:08,160 --> 00:17:11,119
So let's require the package here.

246
00:17:11,130 --> 00:17:12,150
Cost.

247
00:17:13,160 --> 00:17:14,690
Cookie parser.

248
00:17:15,569 --> 00:17:22,680
Is equal to require the package as cookie parcel as that.

249
00:17:22,680 --> 00:17:27,420
And I'm going to pass cookie parcel as it mature and that is it.

250
00:17:27,420 --> 00:17:30,260
So here these are our words here.

251
00:17:30,270 --> 00:17:31,620
Let's say pass.

252
00:17:32,190 --> 00:17:33,030
Cookie.

253
00:17:33,820 --> 00:17:34,450
Cookies.

254
00:17:34,450 --> 00:17:37,600
So app tarts use.

255
00:17:37,990 --> 00:17:43,840
Then you pass in the cookie parser as a method or function.

256
00:17:43,840 --> 00:17:45,350
So now here we go.

257
00:17:45,370 --> 00:17:47,190
So now let's open the terminal.

258
00:17:47,200 --> 00:17:50,830
And now let's try to hit the endpoint, slash protected.

259
00:17:50,860 --> 00:17:54,910
Now let's check the terminal where we got undefined.

260
00:17:54,940 --> 00:17:55,420
Sorry.

261
00:17:55,420 --> 00:17:59,750
On my side is supposed to be rec dot cookies.

262
00:17:59,770 --> 00:18:00,340
Yeah.

263
00:18:00,460 --> 00:18:04,360
So let's refresh the page by hitting the endpoint.

264
00:18:04,360 --> 00:18:10,600
And now you see that I have the user details inside our root.

265
00:18:10,930 --> 00:18:20,350
But if I turn the cookie parser off like that and I made the request to the root, let's see.

266
00:18:20,620 --> 00:18:22,500
It can see that it is undefined.

267
00:18:22,510 --> 00:18:29,960
So this shows that cookie parser allows us to retrieve the cookie from the browser and that is it.

268
00:18:29,980 --> 00:18:32,440
So here how can we protect?

269
00:18:32,800 --> 00:18:39,820
First of all, we can check if there is a property on the foo name or the user name and that way we

270
00:18:39,820 --> 00:18:43,290
are going allow you to want to access that.

271
00:18:43,300 --> 00:18:44,590
So here we go.

272
00:18:44,650 --> 00:18:48,320
So now we can find the user under here.

273
00:18:48,340 --> 00:18:50,200
So let me call up this one.

274
00:18:50,350 --> 00:18:53,680
And now how are we going to implement that?

275
00:18:53,860 --> 00:18:55,180
So here we go.

276
00:18:55,630 --> 00:19:08,290
Const is equal to user, which is equal to rec dot cookies and I only need the user name only from the

277
00:19:08,290 --> 00:19:09,980
cookie like that.

278
00:19:10,000 --> 00:19:14,880
So here, if there is user name, it simply means that the user has logged in.

279
00:19:14,890 --> 00:19:15,430
Right?

280
00:19:15,430 --> 00:19:16,610
So here we go.

281
00:19:16,630 --> 00:19:24,490
So we can pass that one even to the templates as that as a screen agreement, as user.

282
00:19:24,700 --> 00:19:25,450
Like that.

283
00:19:25,450 --> 00:19:31,750
So on a template, you are going to dynamically render a text based on the status.

284
00:19:31,990 --> 00:19:36,760
So here before we even let's remove this one.

285
00:19:37,240 --> 00:19:45,610
Before we even display this one or this text, let's wrap this one or let me have some room here and

286
00:19:45,610 --> 00:19:46,600
show you what I mean.

287
00:19:46,750 --> 00:19:52,060
So what we are going to do is that we are going to display a text.

288
00:19:52,060 --> 00:19:56,950
Each one says that you are not.

289
00:19:59,350 --> 00:20:00,070
Locked.

290
00:20:02,080 --> 00:20:04,390
Locked in like that.

291
00:20:04,480 --> 00:20:08,380
And if you are looking, we are going to display this work.

292
00:20:08,560 --> 00:20:10,270
So how are you going to do it?

293
00:20:10,510 --> 00:20:14,040
So let's use the Aegis template or syntax.

294
00:20:14,800 --> 00:20:17,800
So here we are going to write JavaScript inside here.

295
00:20:17,800 --> 00:20:26,740
So if there is a user on a template, then we will go ahead and then display this one here.

296
00:20:26,770 --> 00:20:28,810
Cut it and place it here.

297
00:20:29,020 --> 00:20:32,710
So here, let's close the Aegis syntax here.

298
00:20:33,310 --> 00:20:34,270
Likewise.

299
00:20:34,270 --> 00:20:34,990
Here.

300
00:20:34,990 --> 00:20:36,800
Also good.

301
00:20:36,820 --> 00:20:40,720
Otherwise, go ahead and render this or let's bring the arrows.

302
00:20:40,720 --> 00:20:51,370
Also here, arrows and make sure that you close this tags and close this one or so like that.

303
00:20:51,370 --> 00:20:54,790
And let's cut this one and place it inside here.

304
00:20:54,850 --> 00:20:57,160
Now, moment of truth.

305
00:20:57,250 --> 00:21:05,500
So if I go to the page, you will see that when I refresh it, I see where where from this error.

306
00:21:05,530 --> 00:21:09,070
Let's see our code or bottom side.

307
00:21:09,100 --> 00:21:13,330
We need to pass in as object to the templates as that.

308
00:21:13,330 --> 00:21:16,570
So now let's save it and now let's refresh it.

309
00:21:16,840 --> 00:21:19,260
And we see that we have welcome.

310
00:21:19,570 --> 00:21:23,680
But if I remove this cookie, let me remove the user name.

311
00:21:23,680 --> 00:21:25,480
And now let's refresh it.

312
00:21:25,480 --> 00:21:29,080
And we see that you are not logged in.

313
00:21:29,320 --> 00:21:34,510
So it means that upon logging into we need to save the user into the cookies.

314
00:21:34,510 --> 00:21:38,380
So here this what we can do, we can copy this one.

315
00:21:38,620 --> 00:21:46,360
And now upon logging into where is the logging route, which is let's have some room here, which is

316
00:21:46,360 --> 00:21:53,560
this one now before sending which is here, we need to set the user into cookies.

317
00:21:53,560 --> 00:22:01,450
So we are going to use user found here, user found going to be this ones and as that.

318
00:22:01,450 --> 00:22:03,580
So I want to save the password again.

319
00:22:03,580 --> 00:22:06,940
So let's remove the password from the cookies as that.

320
00:22:06,940 --> 00:22:10,690
So let's go ahead and then continue the logging in.

321
00:22:10,900 --> 00:22:19,030
So log in here, Lizzy, and then one, two, three, four, five and then click on log in where I got

322
00:22:19,030 --> 00:22:19,930
some error.

323
00:22:20,050 --> 00:22:22,200
So let's check the terminal here.

324
00:22:22,210 --> 00:22:24,040
Where are we getting wrong.

325
00:22:24,070 --> 00:22:26,560
User found is not.

326
00:22:27,100 --> 00:22:28,270
Oh I have user found.

327
00:22:28,270 --> 00:22:28,980
User found.

328
00:22:28,990 --> 00:22:35,710
Sorry guys it's about the redirection is going to be user found.

329
00:22:35,710 --> 00:22:36,220
Yeah.

330
00:22:36,850 --> 00:22:37,350
Good.

331
00:22:37,360 --> 00:22:38,620
So let's try again.

332
00:22:39,590 --> 00:22:40,580
Refresh it.

333
00:22:42,740 --> 00:22:44,870
And now let's go to the list.

334
00:22:44,870 --> 00:22:48,530
Remove the user here or the cookies.

335
00:22:48,710 --> 00:22:50,750
And now let's go to log in.

336
00:22:51,670 --> 00:22:52,450
Lizzie.

337
00:22:52,450 --> 00:22:58,420
One, two, three, four, five and log in and now let's go to protected and now work on.

338
00:22:58,420 --> 00:23:00,520
So now everything is working.

339
00:23:00,520 --> 00:23:04,180
So what about the if I go to log in sorry.

340
00:23:04,180 --> 00:23:08,080
When I log in and I want to go to the profile page.

341
00:23:08,410 --> 00:23:09,370
Let's see.

342
00:23:10,150 --> 00:23:11,950
Now I want to look out.

343
00:23:11,950 --> 00:23:17,320
When I click on logout, it means I want to remove the cookies from the browser.

344
00:23:17,320 --> 00:23:19,840
So let's see how we can implement the logout.

