Is there no option to access request user in middleware level to make some checks? I have tried global and api level middlewares but in both cases there is no ctx ![:man_shrugging: :man_shrugging:](https://forum.strapi.io/images/emoji/twitter/man_shrugging.png?v=12)
This topic has been created from a Discord post (1221789942842134610) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord
Has to done with Policies instead
Hey fellow LOL player, you can indeed acces the user from middlewares.
I do it in the following manner:
const { user } = context.state;
Thank you
"use strict";
module.exports = (config, { strapi }) => {
return async (ctx, next) => {
const { user } = ctx.state;
console.log("ctx.state:", ctx.state);
await next();
};
};```
Thanks for the answer <@748491524249092096> . Also, you can use the strapi.requestContext.get()
to get the request context as long as the middleware is called in the context of an HTTP request.
const ctx = strapi.requestContext.get();
console.log(ctx.state.user);