// Go to next policy or will reach the controller's action.
return await next();
}
ctx.unauthorized(`You're not logged in!`);
};
```
In this example, we are verifying that a session is open. If it is the case, we call the `next()` method that will execute the next policy or controller's action. Otherwise, a 401 error is returned.
::: note
You can access to any controllers, services or models thanks to the global variable `strapi` in a policy.
:::
## Usage
To apply policies to a route, you need to associate an array of policies to it. As explained in the [policies' concepts](../concepts/concepts.md#policies), there are two kinds of policies: global or scoped.
### Global policies
Refer to the [concept](../concepts/concepts.md#policies) for details.
The global policies can be associated to any routes in your project.
Before executing the `find` action in the `Car.js` controller, the global policy `isAuthenticated` located in `./config/policies/isAuthenticated.js` will be called.
::: note
You can put as much policy you want in this array. However be careful about the performance impact.
:::
### Plugins policies
Plugins can add and expose policies into your app. For example, the plugin `Auth` (COMING SOON) comes with several useful policies to ensure that the user is well authenticated or has the rights to perform an action.
The policy `isAdmin` located in `./api/car/config/policies/isAdmin.js` will be executed before the `find` action in the `Car.js` controller.
::: note
The policy `isAdmin` can only be applied to the routes defined in the `/api/car` folder.
:::
## Advanced usage
As it's explained above, the policies are executed before the controller's action. It looks like an action that you can make `before` the controller's action. You can also execute a logic `after`.