Adds Roles and Permissions collections to Payload and injects a roles relationship field into your auth collection, saved to the JWT. Access control is done by checking permissions rather than roles, using the checkPermission wrapper and hasPermission helper. Permissions can carry conditions set in the admin UI that map to Payload Where queries. Requires Payload 3.85 or newer.
RBAC plugin for payloadcms
Installation
npm i payload-rbac-plugin6
Stars
0
Forks
0
Open Issues
6 months ago
Last Updated
38
Weekly Downloads
v1.1.0
npm Version
91.1 KB
Unpacked Size
0
Dependencies
6+2 since Sep 7
| Date | Stars |
|---|---|
| Dec 6, 2026 | 6 |
| Dec 5, 2026 | 6 |
| Dec 4, 2026 | 6 |
| Dec 3, 2026 | 6 |
| Dec 2, 2026 | 6 |
| Dec 1, 2026 | 6 |
| Nov 30, 2026 | 6 |
| Nov 29, 2026 | 6 |
| Nov 28, 2026 | 6 |
| Nov 27, 2026 | 6 |
| Nov 26, 2026 | 6 |
| Nov 25, 2026 | 6 |
| Nov 24, 2026 | 6 |
| Nov 23, 2026 | 6 |
| Nov 22, 2026 | 6 |
| Nov 21, 2026 | 6 |
| Nov 20, 2026 | 6 |
| Nov 19, 2026 | 6 |
| Nov 18, 2026 | 6 |
| Nov 17, 2026 | 6 |
| Nov 16, 2026 | 6 |
| Nov 15, 2026 | 6 |
| Nov 14, 2026 | 6 |
| Nov 13, 2026 | 6 |
| Nov 12, 2026 | 6 |
| Nov 11, 2026 | 6 |
| Nov 10, 2026 | 6 |
| Nov 9, 2026 | 6 |
| Nov 8, 2026 | 6 |
| Nov 7, 2026 | 6 |
| Nov 6, 2026 | 6 |
| Nov 5, 2026 | 6 |
| Nov 4, 2026 | 6 |
| Nov 3, 2026 | 6 |
| Nov 2, 2026 | 6 |
| Nov 1, 2026 | 6 |
| Oct 31, 2026 | 6 |
| Oct 30, 2026 | 6 |
| Oct 29, 2026 | 6 |
| Oct 28, 2026 | 6 |
| Oct 27, 2026 | 6 |
| Oct 26, 2026 | 6 |
| Oct 25, 2026 | 6 |
| Oct 24, 2026 | 6 |
| Oct 23, 2026 | 6 |
| Oct 22, 2026 | 6 |
| Oct 21, 2026 | 6 |
| Oct 20, 2026 | 6 |
| Oct 19, 2026 | 6 |
| Oct 18, 2026 | 6 |
| Oct 17, 2026 | 6 |
| Oct 16, 2026 | 6 |
| Oct 15, 2026 | 5 |
| Oct 14, 2026 | 5 |
| Oct 13, 2026 | 5 |
| Oct 12, 2026 | 4 |
| Oct 11, 2026 | 4 |
| Oct 10, 2026 | 4 |
| Oct 9, 2026 | 4 |
| Oct 8, 2026 | 4 |
| Oct 7, 2026 | 4 |
| Oct 6, 2026 | 4 |
| Oct 5, 2026 | 4 |
| Oct 4, 2026 | 4 |
| Oct 3, 2026 | 4 |
| Oct 2, 2026 | 4 |
| Oct 1, 2026 | 4 |
| Sep 30, 2026 | 4 |
| Sep 29, 2026 | 4 |
| Sep 28, 2026 | 4 |
| Sep 27, 2026 | 4 |
| Sep 26, 2026 | 4 |
| Sep 25, 2026 | 4 |
| Sep 24, 2026 | 4 |
| Sep 23, 2026 | 4 |
| Sep 22, 2026 | 4 |
| Sep 21, 2026 | 4 |
| Sep 20, 2026 | 4 |
| Sep 19, 2026 | 4 |
| Sep 18, 2026 | 4 |
| Sep 17, 2026 | 4 |
| Sep 16, 2026 | 4 |
| Sep 15, 2026 | 4 |
| Sep 14, 2026 | 4 |
| Sep 13, 2026 | 4 |
| Sep 12, 2026 | 4 |
| Sep 11, 2026 | 4 |
| Sep 10, 2026 | 4 |
| Sep 9, 2026 | 4 |
| Sep 8, 2026 | 4 |
| Sep 7, 2026 | 4 |
38+27 since Sep 7
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 38 |
| Dec 5, 2026 | 18 |
| Dec 4, 2026 | 20 |
| Dec 3, 2026 | 22 |
| Dec 2, 2026 | 33 |
| Dec 1, 2026 | 50 |
| Nov 30, 2026 | 54 |
| Nov 29, 2026 | 54 |
| Nov 28, 2026 | 41 |
| Nov 27, 2026 | 38 |
| Nov 26, 2026 | 34 |
| Nov 25, 2026 | 23 |
| Nov 24, 2026 | 6 |
| Nov 23, 2026 | 3 |
| Nov 22, 2026 | 5 |
| Nov 21, 2026 | 8 |
| Nov 20, 2026 | 8 |
| Nov 19, 2026 | 9 |
| Nov 18, 2026 | 20 |
| Nov 17, 2026 | 20 |
| Nov 16, 2026 | 26 |
| Nov 15, 2026 | 23 |
| Nov 14, 2026 | 21 |
| Nov 13, 2026 | 22 |
| Nov 12, 2026 | 32 |
| Nov 11, 2026 | 24 |
| Nov 10, 2026 | 29 |
| Nov 9, 2026 | 27 |
| Nov 8, 2026 | 32 |
| Nov 7, 2026 | 37 |
| Nov 6, 2026 | 36 |
| Nov 5, 2026 | 28 |
| Nov 4, 2026 | 25 |
| Nov 3, 2026 | 20 |
| Nov 2, 2026 | 27 |
| Nov 1, 2026 | 22 |
| Oct 31, 2026 | 19 |
| Oct 30, 2026 | 20 |
| Oct 29, 2026 | 17 |
| Oct 28, 2026 | 17 |
| Oct 27, 2026 | 21 |
| Oct 26, 2026 | 10 |
| Oct 25, 2026 | 11 |
| Oct 24, 2026 | 9 |
| Oct 23, 2026 | 7 |
| Oct 22, 2026 | 9 |
| Oct 21, 2026 | 10 |
| Oct 20, 2026 | 6 |
| Oct 19, 2026 | 6 |
| Oct 18, 2026 | 5 |
| Oct 17, 2026 | 5 |
| Oct 16, 2026 | 5 |
| Oct 15, 2026 | 4 |
| Oct 14, 2026 | 3 |
| Oct 13, 2026 | 3 |
| Oct 12, 2026 | 2 |
| Oct 11, 2026 | 3 |
| Oct 10, 2026 | 2 |
| Oct 9, 2026 | 2 |
| Oct 8, 2026 | 2 |
| Oct 7, 2026 | 2 |
| Oct 6, 2026 | 4 |
| Oct 5, 2026 | 8 |
| Oct 4, 2026 | 23 |
| Oct 3, 2026 | 25 |
| Oct 2, 2026 | 28 |
| Oct 1, 2026 | 32 |
| Sep 30, 2026 | 33 |
| Sep 29, 2026 | 31 |
| Sep 28, 2026 | 27 |
| Sep 27, 2026 | 14 |
| Sep 26, 2026 | 15 |
| Sep 25, 2026 | 13 |
| Sep 24, 2026 | 8 |
| Sep 23, 2026 | 7 |
| Sep 22, 2026 | 19 |
| Sep 21, 2026 | 19 |
| Sep 20, 2026 | 23 |
| Sep 19, 2026 | 20 |
| Sep 18, 2026 | 24 |
| Sep 17, 2026 | 31 |
| Sep 16, 2026 | 37 |
| Sep 15, 2026 | 27 |
| Sep 14, 2026 | 30 |
| Sep 13, 2026 | 24 |
| Sep 12, 2026 | 25 |
| Sep 11, 2026 | 20 |
| Sep 10, 2026 | 13 |
| Sep 9, 2026 | 10 |
| Sep 8, 2026 | 10 |
| Sep 7, 2026 | 11 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1257615366-root)<a href="https://payloaddirectory.dev/plugins/1257615366-root"><img src="https://payloaddirectory.dev/badge/1257615366-root.svg" alt="Payload Directory"></a>README
A professional, database-backed Role-Based Access Control (RBAC) system for Payload CMS (v3).
This plugin emphasizes checking permissions instead of roles to avoid hard-coded authorization logic in your source code, making your access control highly scalable, modular, and dynamic.
Roles and Permissions collections.roles relationship field into your target auth collection (e.g., users) with saveToJWT: true for zero-cost runtime checks.posts:create, posts:read, posts:update, posts:delete) at once.type, collectionName, CRUD checkboxes) are purely for the UI and are never saved to your database, keeping your collections clean.Roles and Permissions schemas.hideRoles, hidePermissions) dynamically or statically for the RBAC admin interface.hasPermission) and access control wrappers (checkPermission).Shows flat generated permissions (e.g. posts:create, posts:read) and legacy system permissions.

Create individual custom permissions.

Select a collection and check CRUD actions to instantly generate multiple permissions.

Displays roles and all permissions associated with them.

Assign permissions directly to roles in the admin UI.

Add the plugin to your project:
pnpm add payload-rbac-plugin
# or
npm install payload-rbac-plugin
# or
yarn add payload-rbac-plugin
Import and configure the plugin in your payload.config.ts:
import { buildConfig } from 'payload'
import { rbac, hasPermission } from 'payload-rbac-plugin'
export default buildConfig({
collections: [
{
slug: 'posts',
fields: [],
},
],
plugins: [
rbac({
enabled: true,
// Optional configurations:
authCollectionSlug: 'users', // Default: 'users'
rolesCollectionSlug: 'roles', // Default: 'roles'
permissionsCollectionSlug: 'permissions', // Default: 'permissions'
// Control access/visibility of the RBAC panel:
hidePermissions: ({ user }) => !hasPermission(user, 'access:permissions'),
hideRoles: ({ user }) => !hasPermission(user, 'access:roles'),
}),
],
})
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Enable or disable the plugin. |
authCollectionSlug | string | 'users' | The collection slug representing the users collection. |
rolesCollectionSlug | string | 'roles' | The slug for the automatically injected Roles collection. |
permissionsCollectionSlug | string | 'permissions' | The slug for the automatically injected Permissions collection. |
rolesFields | Field[] | [] | Extra custom fields to inject into the Roles collection. |
permissionsFields | Field[] | [] | Extra custom fields to inject into the Permissions collection. |
hideRoles | boolean | ((args: { user: any }) => boolean) | false | Hide the Roles collection from the sidebar navigation. |
hidePermissions | boolean | ((args: { user: any }) => boolean) | false | Hide the Permissions collection from the sidebar navigation. |
permissionsAccess | CollectionConfig['access'] | { ... } | Access control functions for the generated Permissions collection (defaults to public). |
rolesAccess | CollectionConfig['access'] | { ... } | Access control functions for the generated Roles collection (defaults to public). |
You can protect collections using the checkPermission Higher-Order Function. It returns a standard Payload Access control resolver.
import { checkPermission } from 'payload-rbac-plugin'
export const PostsCollection = {
slug: 'posts',
access: {
create: checkPermission('posts:create'),
read: checkPermission('posts:read'),
update: checkPermission('posts:update'),
delete: checkPermission('posts:delete'),
},
fields: [],
}
The checkPermission wrapper natively supports Attribute-Based Access Control (ABAC). If an administrator assigns a permission with conditions in the Admin UI (e.g. sender equals {{user.id}}), checkPermission will automatically map it to a Payload Where object without any code changes!
If you need to construct these queries manually outside of standard access control, you can use the getPermissionQuery utility:
import { getPermissionQuery } from 'payload-rbac-plugin'
export const CustomEndpoint = async (req) => {
// Returns `true`, `false`, or a Payload Where object depending on UI conditions
const accessQuery = getPermissionQuery(req.user, 'posts:read')
if (!accessQuery) return Response.json({ error: 'Forbidden' }, { status: 403 })
const posts = await req.payload.find({
collection: 'posts',
where: typeof accessQuery === 'object' ? accessQuery : undefined,
})
}
When defining conditional Values in the UI, you can inject variables:
{{user.id}} - Replaced with the current user's ID{{user.roles}} - Replaced with an array of the user's role IDs (useful for the in operator){{user.role}} - Replaced with the user's role ID (if using a single custom role field)true / false - Properly parsed into booleans (useful for the exists operator)hasPermission)For custom endpoints, hooks, or conditionally rendering logic, use the hasPermission utility:
import { hasPermission } from 'payload-rbac-plugin'
const myCustomEndpoint = (req, res) => {
const user = req.user
if (hasPermission(user, 'export:reports')) {
// allow operation
} else {
res.status(403).send('Forbidden')
}
}
When navigating to the Permissions collection in your Payload Admin panel:
Type select box (visible only during document creation).posts) in the Collection Name field.create, read).beforeChange hook that creates individual flat records (posts:create, posts:read) in the database, and avoids saving any temporary helper fields to the database.If you are developing this plugin locally, you can run the test suite:
# Run unit and integration tests
pnpm test:int
# Run tests in watch mode
pnpm test:int --watch
MIT
multi tenant
Manage multiple tenants and tenant-scoped content from a single Payload admin panel
100165.4k/wk46.1kv3 v4
rbac
Database-driven role-based access control with a per-collection permissions matrix and admin localization
5915/wk0v4
payload plugin rbac
Database-driven role-based access control with a permission matrix and data scopes for Payload collections
5874/wk10v3
payload gatekeeper
Role-based access control for Payload v3 with wildcard permissions, auto role assignment and a managed Roles collection
39199/wk25v3
payload warding
Collection-backed RBAC plugin that generates user and role collections with per-field and per-endpoint permissions
3910/wk17v2
payload plugin rbac ui
Permissions matrix UI for a Payload Roles collection with auto-discovered, validated permission strings
38172/wk1v3