How to filter content from find apis so that only owner can see that

System Information
  • Strapi Version: 4.3.9
  • Operating System: Ubuntu 22
  • Database: Mysql
  • Node Version: 16.14
  • NPM Version: 8.5
  • Yarn Version:

I have a field “Author” in “article” content-type.
The business logic is such that only author can view/find his articles, not others.
Currently, I have to apply custom logic in every find API, and at other content-types that are related to article. To filter out content not related to author.
My custom logic adds filters in controllers.

The problem is that this custom code is increasing.
Is there a better way like policy or middleware, so that I don’t have to add custom code in every such controllers. And, it is handled at some common place.

Thanks

Hi, I hope this helps:

There is a link to an example repository by @msoler75

I’m doing the same. I have other content-types as well, that depends upon this Author field. I have to repeat this code.
I thought of having some other approach.

Anyway, thanks.