My requirement is to list all the users created by the current logged in user in the payload users page. I tried creating before read hook and filter users only created by the current logged in users and return only them. But it seems to be not working (still shows all the users in the database)
I added created By and updated By fields in the users collection.
- attempted way
Couple things going on here. If you want to restrict users to seeing only the users they have created, you should use access control to do that. For that you would just return the
wherepart of your query.
If you wanted to find the users (but not restrict) you should use a query constraint when fetching.
Check out this page in the docs that talks about querying:
https://payloadcms.com/docs/queries/overviewThank you. It worked. I created a custom access function with queries.
If someone is struggling to figure out,
https://github.com/payloadcms/access-control-demo/blob/master/src/access/isAdminOrSelf.tsStar
Discord
online
Get dedicated engineering support directly from the Payload team.