Schema for disable specific fields for different roles in payload CMS(role wise access for fields).

Update the schema for the field you have to disable for other users.

{

      name: ‘approvalstatus’,

      type: ‘select’,

      options: [

        { label: ‘Entered’, value: ‘entered’ },

        { label: ‘Submit’, value: ‘submit’ },

        { label: ‘Approved’, value: ‘approved’ },

        { label: ‘Declined’, value: ‘declined’ },

      ],

      label: ‘Approval Status’,

      access:{

        update:checkAdminRole

    },

set the checkadmin role as

const checkAdminRole = ({ req: { user } }) => {

    return user?.role?.includes(‘admin’);

  };

the users schema has to be well organized for setting the functionality.

Leave a comment

Your email address will not be published. Required fields are marked *