Access permission for a collection

default discord avatar
generator101
2 months ago
2

I want to create a collection called Projects, I want all users to be able to create projects but I want only users to access their own projects and not every project (ex: projects created by other users).


What should I set the access to? Is there an example that has been done for a collection?

  • discord user avatar
    jarrod_not_jared
    Payload Team
    2 months ago

    You will want to add a field to the project

    createdBy

    and then set that field in a beforeChange hook, using the user on the

    req


    From there you can set up your read access control on the collection to return a query constraint where the user requesting the doc equals that field

  • default discord avatar
    generator101
    2 months ago

    @jarrod_not_jared thanks, is there an example for this access?



    oh I found this

    https://payloadcms.com/blog/build-your-own-rbac
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

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