1
00:00:08,680 --> 00:00:10,150
Welcome back.

2
00:00:10,180 --> 00:00:19,810
In this video, let's get started with cookie based authentication, where we are going to improve the

3
00:00:19,810 --> 00:00:25,270
previous concept by adding what is called cookie based authentication to it.

4
00:00:25,690 --> 00:00:26,080
All right.

5
00:00:26,080 --> 00:00:30,340
So let's see, what is cookie or what are cookies?

6
00:00:30,430 --> 00:00:32,590
Well, here we go.

7
00:00:32,920 --> 00:00:42,370
Cookies in programming is not real cookies, as you see in reality, but instead it is a string of characters.

8
00:00:42,370 --> 00:00:43,930
But let's see in details.

9
00:00:44,080 --> 00:00:54,280
So cookies are a small text file that is stored on your browser, which contains data from the websites

10
00:00:54,280 --> 00:00:55,810
that you visit.

11
00:00:56,260 --> 00:01:05,410
So a cookie is a kind of ways of storing data, and we can use cookies to implement what is called authentication.

12
00:01:05,620 --> 00:01:08,270
If cookies are a file that stores data.

13
00:01:08,290 --> 00:01:16,690
It means that we can store the user login details onto the file and upon every request we are going

14
00:01:16,690 --> 00:01:21,210
to check if there is user inside the cookies and that is it.

15
00:01:21,220 --> 00:01:24,990
So let's look at some facts about cookies.

16
00:01:25,000 --> 00:01:28,750
That is some properties and why do we need cookies?

17
00:01:28,780 --> 00:01:34,840
The first point is that it is used in session management.

18
00:01:35,020 --> 00:01:43,360
Like I would say that servers are stateless, but if we are able to implement session, it means that

19
00:01:43,360 --> 00:01:47,590
our server will be able to remember the log in user.

20
00:01:47,590 --> 00:01:55,180
So upon every request our server is going to check the session if there is a user and I'll show it to

21
00:01:55,180 --> 00:01:58,240
you with code, let's continue on.

22
00:01:58,450 --> 00:02:06,640
The next point is that cookies are stored with key value per and with some optional attributes, meaning

23
00:02:06,640 --> 00:02:15,610
that we can save the user name with a value and a password with a value also inside our browsers.

24
00:02:15,730 --> 00:02:24,670
The next point is that we don't need to install any package before we can use cookies by default.

25
00:02:24,670 --> 00:02:32,650
Express has this one for us, so to use cookies, you don't need to install any package from NPM or

26
00:02:32,650 --> 00:02:38,830
from the core modules, but instead express get us covered.

27
00:02:38,860 --> 00:02:48,460
The next point is that but we need a package to send back the cookie back to the server upon each request

28
00:02:48,940 --> 00:02:54,130
so our server can generate a cookie by default.

29
00:02:54,430 --> 00:03:02,680
But if you want to get a cookie from the browser into our server to check if a user has been logged

30
00:03:02,680 --> 00:03:10,270
in, we need a third party package called Cookie Parcel, meaning we are going to pass the cookie in

31
00:03:10,270 --> 00:03:16,480
the browser and then use inside our route to check the user upon each request.

32
00:03:16,480 --> 00:03:18,310
And I'll show you this one also.

33
00:03:18,640 --> 00:03:25,120
The next point is that cookies can be used to keep track user activity on the side.

34
00:03:25,240 --> 00:03:34,390
So in this case, the application can provide a personalized experience for the user, such as remembering

35
00:03:34,420 --> 00:03:37,900
the user name or any other preferences.

36
00:03:37,900 --> 00:03:42,310
And I believe you see some of these features in most applications.

37
00:03:42,400 --> 00:03:51,160
The next point is that we use cookies to store data about the current user, and this is what we call

38
00:03:51,160 --> 00:03:54,310
the use insertion management.

39
00:03:54,310 --> 00:04:01,120
So this information can be used to analyze website usage and improve the user experience.

40
00:04:01,300 --> 00:04:06,400
So additionally, cookies can be used to serve target advertising to users.

41
00:04:06,700 --> 00:04:12,640
So most advertising companies like YouTube and Facebook, they use cookies.

42
00:04:12,640 --> 00:04:18,760
In that way they can display a specific advert based on the need or your location.

43
00:04:18,880 --> 00:04:26,860
So with this one being said, the next video, let's see how we can get started with cookie based authentication.

