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 to particular page

default discord avatar
bhavikak.last year
4

is it possible to possible to give only edit access on particular page

  • default discord avatar
    dr_mintlast year

    Hi! Yes, with access functions, you can either return a boolean or an query constraint

    https://payloadcms.com/docs/access-control/collections#update

    The query constraint can be used to limit which document(s) a user can read/edit

  • default discord avatar
    bhavikak.last year
    @306041255316553729

    but it's for collection ri8?



    i want to apply at page level

  • default discord avatar
    dr_mintlast year

    The query constraint allows you to filter which pages you want to give access. If you want to give access to a single page based on its ID, you may use the following query

    { id: { equals: "idToGiveAccessTo" } }
  • default discord avatar
    bhavikak.last year

    thanks

    @306041255316553729

    i'll try



    hello

    @306041255316553729

    i tried but i got id as undefined



    i have to use hook or accessControl?



    i'm getting confuse



    i want to allow only career page access to the user those have a 'hr' role



    import type { Access } from 'payload/config';



    import { checkRole } from './checkRole';



    const adminAndHrAndUser: Access = ({ req: { user }, id }) => {


    if (user) {


    if (checkRole(['admin'], user)) {


    return true;


    }



    if (checkRole(['hr'], user)) {


    if (id === '64df354b4574c2098e2c196a') {


    return true;


    }


    return {


    id: user.id,


    };


    }


    return {


    id: user.id,


    };


    }



    return false;


    };



    export default adminAndHrAndUser;



    this is my code

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.