Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Access control: add limit restriction

default discord avatar
Sandro Wegmannlast year
5

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
    noheadphoneslast year

    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



    https://payloadcms.com/docs/rest-api/overview#custom-endpoints
  • default discord avatar
    Jarrodlast year

    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

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team..