System Information
  • 4:
  • Linux:
  • Postgres:
  • 18.19.1:
  • 10.2.4:

Hello. I am new to Strapi and I am trying to create a middleware that enforces the isOwner policy in an endpoint.

I have followed the strapi v4 documentation to do this but for some reason I have not had any luck.

In the documentation, the line

const user = ctx.state.user;

is used to get the user information(as per Requests and Responses | Strapi Documentation).

However, in the next lines, the line

if ( !==

is used to get the request user’s id, but that gives me an error saying that it “Cannot read properties of undefined (reading ‘id’)”.
In the previously linked documentation the parameter “id” for ctx.state.user is not present and that makes me think that it is accesed in another way. can someone point me to some resources to solve this?
Thanks in advanced.