In this video, let's create a murderer to check if a user is an admin.
In that case, the user can go ahead and delete a post.
So here we go.
This is where we left from the previous video.
So let me collapse it.
And now let me create another major word for is admin.
So I'm going to use this same code here, so I'll copy this one.
And down here let me give it a comment.
Says admin is admin is admin middle.
Where now down here let me paste the code.
So let me change this one to is admin.
And now for the object of the user I provide a property call is admin.
Then I will say by default it is true.
So the same thing as the protected.
But instead I have added a property called is admin.
Again, we can get the user from database.
So let's stick to this.
So now for the message.
Let's say that you are not admin, you are not admin.
So how can we use it?
As always, we will locate the root where we want apply the middle word, which is the delete this endpoint.
So here I'll provide it here as is admin and comma separated has that.
So now I'm done with it.
So back to Postman, I can create another endpoint and this one is going to be as delete and the HTTP
method is delete and the path is post and with some ID.
So when I hit send it said that you are not admin.
So let's see if I'm not an admin.
So let's check the middleware.
Yeah, you can see that I'm not making use of the property of admin, but instead I'm making use of
it's log in here so let's change this one to is admin.
Now save it and now let me delete a post and now post deleted.
So it means that that middleware has been caught.
But if I change the property here to force and now back to post mine if I make the request again, you
are not an admin.
Perfect.
So for this one too, we can change as many as middleware we want.
So for this route first we can say that one.
Unless you are log in and after logging in if you are an admin then you can go ahead and delete a post.
So for this one I can make use of the protected route.
First we need to log in and then I'm going to change after logging in.
Unless you are an admin before you can create, before you can delete a post, you can see how we are,
what passing a lot of middleware in the pipeline and there is no limit you can pass in any matter where
you want millions, thousands or hundreds.
It's up to you based on your business logic.
So first is it means that all this middleware need to be passed before you can get the resource.
How awesome it is.
So when I make the request, check it out.
It's sent first.
You must logged in first.
Meaning that first I'm not logged in, which is indeed is false here.
Sorry.
Is this one protected?
Yeah.
When I change this one to true meaning I have logged in now back to postman when I hit Send You are
not an admin.
You can see that I have passed the first middleware but after logging in I'm not an admin so it says
that you are not an admin.
So now again for the admin middleware, let me change this one to true.
Now back to Postman.
Let me hit Send and now I get the post deleted.
How awesome it is in the next video.
Let's see how we can make use of third party middleware also.