Default Roles

Applies default role-based access control to every Payload collection, granting CRUD access to specified roles such as admin and executive.

Community 9 13/wk MIT v0.0.6

Installation

pnpm add @orelo/payload-default-roles

About

Default Roles is a small Payload plugin that fills in access permissions for collections that do not define their own. It iterates over every collection in your config and assigns a default access function to create, update, delete, read, readVersions, and unlock, unless a collection already specifies its own rules for that operation. The default function checks the authenticated user's `role` field against a configurable list of allowed roles. By default those roles are `admin` and `executive`. You can pass a custom `roles` array to match whatever role values your users collection uses. A `ignoredSlugs` option lets you skip specific collections entirely so their access config stays untouched. The plugin targets Payload 1.x and expects your users collection (the one named in `admin.user`, defaulting to `user`) to have a top-level field named `role`. On startup it validates that field exists and throws if it is missing, which is worth knowing if you build the users collection dynamically or rename the field. It is a thin wrapper around the Payload plugin interface, so existing explicit access rules on a collection take precedence because they are spread after the defaults.

Package info

Package name
@orelo/payload-default-roles
Latest version
0.0.6
Unpacked size
8 kB
License
MIT
Weekly downloads
13
Last publish
Dec 1, 2022

Similar plugins

More in Auth