Access control: add limit restriction

default discord avatar
Sandro Wegmann
last month

This might be a dumb question, but how do I add a limit to a query in access control?

I want to restrict read requests to the latest doc in the collection: If someone calls the GET /api/[collection] endpoint, it should only return the latest doc

I've tried modifying the req object, but without success.

  • default discord avatar
    last month

    I think it's not a good idea to limit this (and the way you'd go about it is convoluted) in the access control, as the access control will affect local and other operations in payload

    I would limit read to only the users you want and then create your own API endpoint

    There you have full control over what parameters are available and what gets returned
  • discord user avatar
    Payload Team
    last month

    You could do this, but you would have to set a field on the doc i.e. a checkbox and then when a new doc gets created use a hook to find all the docs where it’s checked, update them to unchecked and check the newest one

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.