Should I add custom data to the ctx.state?

System Information
  • Strapi Version: v4
  • Operating System:
  • Database:
  • Node Version:
  • NPM Version:
  • Yarn Version:

Hello everyone!

I do have a policy for an API where I get some data using the entityService for business-security check, then in the controller I have to access the same data again.

I can use the entityService again but that would be another read from the database, so I was thinking if I can use the data coming from the previously executed policy.

I tried to attach the custom data to the ctx.state in the policy and I was able to read it from the controller… but my question is if this is okay? or there’s another way more “correct” to achieve this?

thank you so much in advance! :smiley: