How to Add Middleware in Strapi to Filter core "Find" Method Results by Owner?

System Information
  • Strapi Version: 4.15.0
  • Operating System: Debian
  • Database: Postgresql
  • Node Version: 21.0
  • NPM Version: 10.1

I’m currently trying to add middleware in Strapi so that when a user utilizes the core “find” method on a collection, they only see records they own.

I’ve already implemented a middleware that works for “update” and “delete” methods based on this documentation. However, I can’t seem to adapt this example for the “find” method as I can’t manipulate the query.

Of course, I have the option to create a custom route to accomplish this, but it would be much more efficient to apply this to existing routes for easier maintenance.

Any insights on how to achieve this?

I already tried to get the result of the controller using await next(); to then filter manually the result; but there aren’t all the necessary field to filter the data like that, and I don’t want theses field to appears to the user.

( I already asked the question on stack overflow last week, but due to the lack of answer I post it here )