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: How to get information about document being accessed

default discord avatar
igormfelast year

Hi,



I'm trying to create an access control function, which must check if the user id of who is making the request matches the user id stored in that specific collection. My question is, how do I access the fields of the collection that is being interacted with?



The function is isCreator bellow:



access: { create: isFunder, update: isCreator, delete: isAdminOrSelf, read: () => true, },

And it to arrive at something like:



export const isCreator: Access = (req) => { return req.req.user.id === document.data.createdBy; }

Where createdBy is a field that stored the id of the user who created it.



Access Control: How to get information about document being accessed

    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.