Ctx.state not populated in strapi V4 middleware

Hello @radu.m ,

we had the same problem today and saw your post. So if you still have issues encountering your problem, try to move “await next ()” above your console.log, like this:

module.exports = (config, { strapi }) => {
  // Add your own logic here.
  return async (ctx, next) => {
   await next(); 
    // this is empty
    console.log('ctx.state', ctx.state)
    strapi.log.info('In foo-middleware middleware.');
  };
};
1 Like