In this video.
Let's talk about how many were works.
So here we go.
Let's take it that we have this client who is using our application, and the application is about a
block application.
So we are going to implement some layers or some security.
First is you need to log in before you can use our application.
So now let's say that this is our server.
Now we have the user here and our server there is express server.
And before a user can create a post, the person needs to log in so the user make a first request and
then before the request gets into the server, it needs to go through some paths or some steps.
And this what you call the middleware steps, because what we want is that you want to check one if
the user is logging, and two, if the user account is verified, and three, if the user is an admin.
Before we can allow you to use our server, these are our lists of business logic.
So let's say that this user has entered his or her login credentials and then before the request or
this one will get into the server.
We have implement a middleware to check if this user login credentials are correct.
So after checking using this middleware for log in, if the user logging credential is wrong, we are
going to throw an error, meaning that the requests have not even go to the server, but because of
the middleware we can end the request here and through error to the user that invalid log in credentials.
But let's say that this user has provided the right login credentials.
In that way, we need to move to the next middleware.
So we are going to call what is called next.
So this means that this particular user has provided the right login credentials, meaning the user
has passed the first middle word.
So in that case, we are going to call next move to the next media world.
And moving to the next middleware, we can throw an error or we can proceed to the next middleware.
So let's say that this user has provided the right logging credentials.
Let's see the flow next is we have also implemented a middleware to check if this user account is verified.
If this user account is verified, then we can connect to move to the next middleware.
But if the user account is not verified, we can through error and give it notice.
And the next we display this error says that not allowed verify your account.
So let's say that the user has to verify his or her account.
Then you are going to call next to move to the next middleware.
Now we have also this middleware in the pipeline.
You can see how we are changing.
Couple of many words before even get to the server.
So many were like like a security or layers where we can use to implement any logic before a user get
to the server.
And let's say that this time around the user is an admin indeed.
Then we are going to call next to move to the next media world.
Finally, the user has been able to get into our server and the server returned the response back to
the user.
So we see how important middleware is, so we can implement millions of millions of middleware in the
chain.
The next video let's see how we can implement middleware.