1
00:00:06,100 --> 00:00:07,660
Welcome back.

2
00:00:07,689 --> 00:00:12,820
In this video, let's see how authentication works.

3
00:00:12,820 --> 00:00:14,950
So let's get started.

4
00:00:15,610 --> 00:00:16,680
All right.

5
00:00:16,690 --> 00:00:25,720
First of all, let's say that we have this particular client or user who is trying to use our application,

6
00:00:25,900 --> 00:00:31,720
and definitely the user is going to use a browser in this case, Google Chrome.

7
00:00:32,290 --> 00:00:39,430
So as soon as the user open our application, a form will be open to the person.

8
00:00:39,640 --> 00:00:43,690
But before logging in, let's see what goes on here.

9
00:00:44,020 --> 00:00:52,510
First, we need a server where the user is going to make a request to and for this particular server.

10
00:00:52,630 --> 00:00:59,800
Let's say we build this server using Node.js and definitely having server alone.

11
00:00:59,800 --> 00:01:02,530
We need a way to store data.

12
00:01:02,620 --> 00:01:05,530
That is why we need data source.

13
00:01:05,530 --> 00:01:09,250
And for this case it's going to be MongoDB.

14
00:01:09,430 --> 00:01:13,030
Now we have these three things in the mix.

15
00:01:13,300 --> 00:01:15,580
So now let's look at the flow.

16
00:01:15,940 --> 00:01:21,460
When a user visit our URL, a form will be open for the user.

17
00:01:22,300 --> 00:01:28,120
So as soon as the user enter the login credentials, let's say email and password.

18
00:01:28,150 --> 00:01:32,890
The first point is that the data will be sent to our server.

19
00:01:33,490 --> 00:01:42,490
Then the server will also send the request to the database to find if this particular user details is

20
00:01:42,490 --> 00:01:44,800
really inside this database.

21
00:01:45,070 --> 00:01:52,870
So if it founds, for example, if the username here is a and then inside the DB is A and the password

22
00:01:52,870 --> 00:01:58,030
is B, and inside DB the password is B, it means that it matches.

23
00:01:58,210 --> 00:02:05,590
So we are going to implement that logic inside our server where we are going to check the user data

24
00:02:05,590 --> 00:02:08,590
against the data inside the database.

25
00:02:08,889 --> 00:02:14,860
So once the user logging credential is wrong, then the process will exit.

26
00:02:15,400 --> 00:02:21,040
So you will see what is called login failed or invalid login credentials.

27
00:02:21,790 --> 00:02:30,430
In this way, the response was sent from the client to the server and server to MongoDB, and then MongoDB

28
00:02:30,430 --> 00:02:32,920
will send the response back to the server.

29
00:02:32,950 --> 00:02:39,130
The server response said, Hey, MongoDB says that we don't know this particular email, so you are

30
00:02:39,130 --> 00:02:40,750
not authorized to log in.

31
00:02:41,020 --> 00:02:45,040
But let's say that the user provides the right logging credentials.

32
00:02:45,040 --> 00:02:53,800
Then the database response we give you to our server and our services that Hey, user MongoDB says that

33
00:02:53,800 --> 00:02:58,570
your data are inside the database so you can go ahead and log in.

34
00:02:58,750 --> 00:03:02,120
So at this point, the user has been, what, log in.

35
00:03:02,140 --> 00:03:10,120
So in a nutshell, when entering your record into our server is going to check if the record the user

36
00:03:10,120 --> 00:03:13,420
is trying to enter is inside our database.

37
00:03:13,450 --> 00:03:16,930
If it is there, then the user will go ahead and then log in.

38
00:03:16,960 --> 00:03:19,670
Otherwise, we're not return error.

39
00:03:19,690 --> 00:03:23,880
So this is a basic flow and this is what we are going to implement.

40
00:03:23,890 --> 00:03:29,440
So where we are going to work on is inside our server here.

41
00:03:30,010 --> 00:03:30,640
All right.

42
00:03:30,640 --> 00:03:37,000
So in the next video, let's get started with the low level authentication where a user is going to

43
00:03:37,000 --> 00:03:40,930
log in with a plain email and then password or username.

44
00:03:40,960 --> 00:03:43,300
Let's get into that in the next video.

