1
00:00:06,040 --> 00:00:07,180
In this video.

2
00:00:07,210 --> 00:00:10,990
Let's talk about how many were works.

3
00:00:10,990 --> 00:00:12,790
So here we go.

4
00:00:13,630 --> 00:00:22,570
Let's take it that we have this client who is using our application, and the application is about a

5
00:00:22,570 --> 00:00:24,220
block application.

6
00:00:24,460 --> 00:00:29,080
So we are going to implement some layers or some security.

7
00:00:29,110 --> 00:00:33,480
First is you need to log in before you can use our application.

8
00:00:33,490 --> 00:00:36,640
So now let's say that this is our server.

9
00:00:36,670 --> 00:00:42,580
Now we have the user here and our server there is express server.

10
00:00:43,060 --> 00:00:51,010
And before a user can create a post, the person needs to log in so the user make a first request and

11
00:00:51,010 --> 00:00:58,090
then before the request gets into the server, it needs to go through some paths or some steps.

12
00:00:58,090 --> 00:01:04,840
And this what you call the middleware steps, because what we want is that you want to check one if

13
00:01:04,840 --> 00:01:12,730
the user is logging, and two, if the user account is verified, and three, if the user is an admin.

14
00:01:12,910 --> 00:01:19,300
Before we can allow you to use our server, these are our lists of business logic.

15
00:01:19,600 --> 00:01:27,280
So let's say that this user has entered his or her login credentials and then before the request or

16
00:01:27,280 --> 00:01:29,470
this one will get into the server.

17
00:01:29,500 --> 00:01:36,100
We have implement a middleware to check if this user login credentials are correct.

18
00:01:36,220 --> 00:01:43,540
So after checking using this middleware for log in, if the user logging credential is wrong, we are

19
00:01:43,540 --> 00:01:50,590
going to throw an error, meaning that the requests have not even go to the server, but because of

20
00:01:50,590 --> 00:02:00,020
the middleware we can end the request here and through error to the user that invalid log in credentials.

21
00:02:00,040 --> 00:02:04,400
But let's say that this user has provided the right login credentials.

22
00:02:04,420 --> 00:02:08,620
In that way, we need to move to the next middleware.

23
00:02:08,770 --> 00:02:12,250
So we are going to call what is called next.

24
00:02:12,490 --> 00:02:19,000
So this means that this particular user has provided the right login credentials, meaning the user

25
00:02:19,000 --> 00:02:21,190
has passed the first middle word.

26
00:02:21,430 --> 00:02:25,810
So in that case, we are going to call next move to the next media world.

27
00:02:26,140 --> 00:02:30,910
And moving to the next middleware, we can throw an error or we can proceed to the next middleware.

28
00:02:31,060 --> 00:02:34,740
So let's say that this user has provided the right logging credentials.

29
00:02:34,750 --> 00:02:44,080
Let's see the flow next is we have also implemented a middleware to check if this user account is verified.

30
00:02:44,140 --> 00:02:50,800
If this user account is verified, then we can connect to move to the next middleware.

31
00:02:51,070 --> 00:02:56,770
But if the user account is not verified, we can through error and give it notice.

32
00:02:56,770 --> 00:03:04,030
And the next we display this error says that not allowed verify your account.

33
00:03:04,420 --> 00:03:08,450
So let's say that the user has to verify his or her account.

34
00:03:08,470 --> 00:03:11,560
Then you are going to call next to move to the next middleware.

35
00:03:11,590 --> 00:03:15,490
Now we have also this middleware in the pipeline.

36
00:03:15,520 --> 00:03:17,500
You can see how we are changing.

37
00:03:17,500 --> 00:03:20,150
Couple of many words before even get to the server.

38
00:03:20,170 --> 00:03:28,330
So many were like like a security or layers where we can use to implement any logic before a user get

39
00:03:28,330 --> 00:03:29,170
to the server.

40
00:03:29,620 --> 00:03:33,360
And let's say that this time around the user is an admin indeed.

41
00:03:33,370 --> 00:03:36,610
Then we are going to call next to move to the next media world.

42
00:03:36,820 --> 00:03:43,810
Finally, the user has been able to get into our server and the server returned the response back to

43
00:03:43,810 --> 00:03:44,590
the user.

44
00:03:44,710 --> 00:03:52,450
So we see how important middleware is, so we can implement millions of millions of middleware in the

45
00:03:52,450 --> 00:03:53,140
chain.

46
00:03:53,350 --> 00:03:57,310
The next video let's see how we can implement middleware.

