Ctx.state.user undefined in context policy custom plugin

Then you can use the admin::hasPermissions policy, which checks if you are logged-in as admin in the Strapi’s UI.

An example of policy applied to a custom route:

{
  "routes": [
    {
      "method": "POST",
      "path": "/email-send",
      "handler": "email-send.send",
      "config": {
        "policies": [["admin::hasPermissions", ["plugins::email-connector.send"]]]
      }
    }
}

Also, if you want to make a request to the API with the Authorization header from Strapi’s UI in react, then you can use the request module which is offered by the strapi-helper-plugin module.
Example of http request from Strapi’s Admin to a custom route:

import { request } from 'strapi-helper-plugin';

request('/email-send', { 
        method: 'POST',
        body: {
          email: email
        }
});

This module includes the Authorization header automatically.

1 Like