1
00:00:05,270 --> 00:00:11,030
In this video, let's create a murderer to check if a user is an admin.

2
00:00:11,060 --> 00:00:15,250
In that case, the user can go ahead and delete a post.

3
00:00:15,260 --> 00:00:16,550
So here we go.

4
00:00:16,730 --> 00:00:19,100
This is where we left from the previous video.

5
00:00:19,100 --> 00:00:20,660
So let me collapse it.

6
00:00:20,660 --> 00:00:24,620
And now let me create another major word for is admin.

7
00:00:24,740 --> 00:00:29,390
So I'm going to use this same code here, so I'll copy this one.

8
00:00:29,390 --> 00:00:31,790
And down here let me give it a comment.

9
00:00:31,790 --> 00:00:38,120
Says admin is admin is admin middle.

10
00:00:38,810 --> 00:00:43,460
Where now down here let me paste the code.

11
00:00:43,460 --> 00:00:47,600
So let me change this one to is admin.

12
00:00:48,020 --> 00:00:54,230
And now for the object of the user I provide a property call is admin.

13
00:00:54,380 --> 00:00:57,860
Then I will say by default it is true.

14
00:00:58,010 --> 00:01:00,680
So the same thing as the protected.

15
00:01:00,680 --> 00:01:03,980
But instead I have added a property called is admin.

16
00:01:03,980 --> 00:01:07,280
Again, we can get the user from database.

17
00:01:07,280 --> 00:01:08,960
So let's stick to this.

18
00:01:09,260 --> 00:01:11,300
So now for the message.

19
00:01:11,300 --> 00:01:19,430
Let's say that you are not admin, you are not admin.

20
00:01:19,430 --> 00:01:21,280
So how can we use it?

21
00:01:21,290 --> 00:01:29,450
As always, we will locate the root where we want apply the middle word, which is the delete this endpoint.

22
00:01:29,600 --> 00:01:35,270
So here I'll provide it here as is admin and comma separated has that.

23
00:01:35,270 --> 00:01:36,920
So now I'm done with it.

24
00:01:36,920 --> 00:01:46,490
So back to Postman, I can create another endpoint and this one is going to be as delete and the HTTP

25
00:01:46,490 --> 00:01:51,680
method is delete and the path is post and with some ID.

26
00:01:51,680 --> 00:01:56,420
So when I hit send it said that you are not admin.

27
00:01:56,630 --> 00:02:00,080
So let's see if I'm not an admin.

28
00:02:00,080 --> 00:02:02,120
So let's check the middleware.

29
00:02:03,140 --> 00:02:09,710
Yeah, you can see that I'm not making use of the property of admin, but instead I'm making use of

30
00:02:09,710 --> 00:02:16,040
it's log in here so let's change this one to is admin.

31
00:02:16,040 --> 00:02:21,290
Now save it and now let me delete a post and now post deleted.

32
00:02:21,890 --> 00:02:25,880
So it means that that middleware has been caught.

33
00:02:25,880 --> 00:02:34,370
But if I change the property here to force and now back to post mine if I make the request again, you

34
00:02:34,370 --> 00:02:36,170
are not an admin.

35
00:02:36,500 --> 00:02:37,310
Perfect.

36
00:02:37,550 --> 00:02:42,980
So for this one too, we can change as many as middleware we want.

37
00:02:43,100 --> 00:02:48,140
So for this route first we can say that one.

38
00:02:48,140 --> 00:02:55,670
Unless you are log in and after logging in if you are an admin then you can go ahead and delete a post.

39
00:02:55,670 --> 00:03:00,080
So for this one I can make use of the protected route.

40
00:03:00,080 --> 00:03:05,300
First we need to log in and then I'm going to change after logging in.

41
00:03:05,300 --> 00:03:13,160
Unless you are an admin before you can create, before you can delete a post, you can see how we are,

42
00:03:13,180 --> 00:03:19,010
what passing a lot of middleware in the pipeline and there is no limit you can pass in any matter where

43
00:03:19,010 --> 00:03:22,220
you want millions, thousands or hundreds.

44
00:03:22,220 --> 00:03:25,100
It's up to you based on your business logic.

45
00:03:25,370 --> 00:03:32,420
So first is it means that all this middleware need to be passed before you can get the resource.

46
00:03:32,420 --> 00:03:33,740
How awesome it is.

47
00:03:33,860 --> 00:03:36,590
So when I make the request, check it out.

48
00:03:36,620 --> 00:03:37,940
It's sent first.

49
00:03:37,940 --> 00:03:39,380
You must logged in first.

50
00:03:39,380 --> 00:03:44,660
Meaning that first I'm not logged in, which is indeed is false here.

51
00:03:44,660 --> 00:03:45,260
Sorry.

52
00:03:45,260 --> 00:03:46,790
Is this one protected?

53
00:03:47,120 --> 00:03:47,480
Yeah.

54
00:03:47,480 --> 00:03:54,560
When I change this one to true meaning I have logged in now back to postman when I hit Send You are

55
00:03:54,560 --> 00:03:55,490
not an admin.

56
00:03:55,490 --> 00:04:02,720
You can see that I have passed the first middleware but after logging in I'm not an admin so it says

57
00:04:02,720 --> 00:04:04,760
that you are not an admin.

58
00:04:04,760 --> 00:04:09,620
So now again for the admin middleware, let me change this one to true.

59
00:04:09,920 --> 00:04:11,480
Now back to Postman.

60
00:04:11,480 --> 00:04:15,080
Let me hit Send and now I get the post deleted.

61
00:04:15,110 --> 00:04:18,140
How awesome it is in the next video.

62
00:04:18,140 --> 00:04:22,220
Let's see how we can make use of third party middleware also.

