strapi / documentation

Strapi Documentation
https://docs.strapi.io
Other
1.03k stars 1.11k forks source link

Instructions on creating a middleware mention read but it probably should be find #2103

Closed ri5h closed 5 months ago

ri5h commented 6 months ago

Link to the documentation page or resource

https://docs.strapi.io/dev-docs/backend-customization/middlewares#restricting-content-access-with-an-is-owner-policy

Describe the bug

In step 7 of documentation link above, under title: Restricting content access with an "is-owner policy", the steps to ensuring the methods to which middleware should apply is probably wrong.

After failing to see a log after adding a method read, I went to typescript types and tried find which worked.

I added some additional context and suggested fixes. let me know if you need further information.

ps. I am probably using @strapi/strapi@4.12.4

Additional context

The route config I used to find this information was in node modules. I tried finding it in github but I don't think I can find a generated type in the monorepo, only relevant file was in a commit which may have been moved/renamed/etc. https://github.com/strapi/strapi/blob/9c79921d22142a5de77ea26151550a14e4b12669/packages/core/types/src/types/core-api/router.ts#L29

Below is how it looks in my node modules.

export interface SingleTypeRouterConfig extends Generic {
  find?: HandlerConfig;
  update?: HandlerConfig;
  delete?: HandlerConfig;
}

export interface CollectionTypeRouterConfig extends Generic {
  find?: HandlerConfig;
  findOne?: HandlerConfig;
  create?: HandlerConfig;
  update?: HandlerConfig;
  delete?: HandlerConfig;
}

Suggested improvements or fixes

Either there was a change in another version which I am not using, maybe later versions use read instead of find, in which case, I am not sure how this could be solved, maybe a version switcher (example: https://laravel.com/docs/11.x/readme) at top is too big of a topic.

If not, just updating it should solve the issue I faced.

Related issue(s)/PR(s)

No response

pwizla commented 5 months ago

You're right, I've just fixed it. Thanks for reporting it!