Adds a role system to your auth collections through a Payload plugin configured with a list of roles. It provides ready-made access control functions such as allow anonymous, allow any user, allow by role, allow by environment variable and block all. Functions accept optional where filters and can be combined with composite helpers. Targets Payload 1.x.
Simple role based access control for your Payload cms
Installation
npm i payload-rbac143
Stars
15
Forks
13
Open Issues
2 years ago
Last Updated
95
Weekly Downloads
v1.0.3
npm Version
39.0 KB
Unpacked Size
0
Dependencies
143+2 since Sep 7
| Date | Stars |
|---|---|
| Dec 6, 2026 | 143 |
| Dec 5, 2026 | 143 |
| Dec 4, 2026 | 143 |
| Dec 3, 2026 | 143 |
| Dec 2, 2026 | 143 |
| Dec 1, 2026 | 143 |
| Nov 30, 2026 | 143 |
| Nov 29, 2026 | 143 |
| Nov 28, 2026 | 143 |
| Nov 27, 2026 | 143 |
| Nov 26, 2026 | 143 |
| Nov 25, 2026 | 143 |
| Nov 24, 2026 | 143 |
| Nov 23, 2026 | 143 |
| Nov 22, 2026 | 143 |
| Nov 21, 2026 | 143 |
| Nov 20, 2026 | 143 |
| Nov 19, 2026 | 143 |
| Nov 18, 2026 | 143 |
| Nov 17, 2026 | 143 |
| Nov 16, 2026 | 143 |
| Nov 15, 2026 | 143 |
| Nov 14, 2026 | 143 |
| Nov 13, 2026 | 143 |
| Nov 12, 2026 | 143 |
| Nov 11, 2026 | 143 |
| Nov 10, 2026 | 143 |
| Nov 9, 2026 | 143 |
| Nov 8, 2026 | 143 |
| Nov 7, 2026 | 142 |
| Nov 6, 2026 | 142 |
| Nov 5, 2026 | 142 |
| Nov 4, 2026 | 142 |
| Nov 3, 2026 | 142 |
| Nov 2, 2026 | 142 |
| Nov 1, 2026 | 142 |
| Oct 31, 2026 | 142 |
| Oct 30, 2026 | 142 |
| Oct 29, 2026 | 142 |
| Oct 28, 2026 | 142 |
| Oct 27, 2026 | 142 |
| Oct 26, 2026 | 142 |
| Oct 25, 2026 | 142 |
| Oct 24, 2026 | 142 |
| Oct 23, 2026 | 142 |
| Oct 22, 2026 | 142 |
| Oct 21, 2026 | 142 |
| Oct 20, 2026 | 142 |
| Oct 19, 2026 | 142 |
| Oct 18, 2026 | 142 |
| Oct 17, 2026 | 142 |
| Oct 16, 2026 | 142 |
| Oct 15, 2026 | 142 |
| Oct 14, 2026 | 142 |
| Oct 13, 2026 | 142 |
| Oct 12, 2026 | 142 |
| Oct 11, 2026 | 142 |
| Oct 10, 2026 | 142 |
| Oct 9, 2026 | 142 |
| Oct 8, 2026 | 142 |
| Oct 7, 2026 | 142 |
| Oct 6, 2026 | 142 |
| Oct 5, 2026 | 142 |
| Oct 4, 2026 | 142 |
| Oct 3, 2026 | 142 |
| Oct 2, 2026 | 142 |
| Oct 1, 2026 | 142 |
| Sep 30, 2026 | 142 |
| Sep 29, 2026 | 142 |
| Sep 28, 2026 | 142 |
| Sep 27, 2026 | 142 |
| Sep 26, 2026 | 142 |
| Sep 25, 2026 | 142 |
| Sep 24, 2026 | 142 |
| Sep 23, 2026 | 142 |
| Sep 22, 2026 | 142 |
| Sep 21, 2026 | 142 |
| Sep 20, 2026 | 142 |
| Sep 19, 2026 | 142 |
| Sep 18, 2026 | 142 |
| Sep 17, 2026 | 142 |
| Sep 16, 2026 | 141 |
| Sep 15, 2026 | 141 |
| Sep 14, 2026 | 141 |
| Sep 13, 2026 | 141 |
| Sep 12, 2026 | 141 |
| Sep 11, 2026 | 141 |
| Sep 10, 2026 | 141 |
| Sep 9, 2026 | 141 |
| Sep 8, 2026 | 141 |
| Sep 7, 2026 | 141 |
Shared by 5 plugins in teunmooij/payload-tools.
95+70 since Sep 7
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 95 |
| Dec 5, 2026 | 63 |
| Dec 4, 2026 | 42 |
| Dec 3, 2026 | 19 |
| Dec 2, 2026 | 21 |
| Dec 1, 2026 | 23 |
| Nov 30, 2026 | 25 |
| Nov 29, 2026 | 29 |
| Nov 28, 2026 | 32 |
| Nov 27, 2026 | 31 |
| Nov 26, 2026 | 30 |
| Nov 25, 2026 | 31 |
| Nov 24, 2026 | 31 |
| Nov 23, 2026 | 25 |
| Nov 22, 2026 | 18 |
| Nov 21, 2026 | 19 |
| Nov 20, 2026 | 27 |
| Nov 19, 2026 | 32 |
| Nov 18, 2026 | 34 |
| Nov 17, 2026 | 33 |
| Nov 16, 2026 | 35 |
| Nov 15, 2026 | 33 |
| Nov 14, 2026 | 31 |
| Nov 13, 2026 | 24 |
| Nov 12, 2026 | 34 |
| Nov 11, 2026 | 29 |
| Nov 10, 2026 | 31 |
| Nov 9, 2026 | 30 |
| Nov 8, 2026 | 42 |
| Nov 7, 2026 | 48 |
| Nov 6, 2026 | 52 |
| Nov 5, 2026 | 44 |
| Nov 4, 2026 | 49 |
| Nov 3, 2026 | 50 |
| Nov 2, 2026 | 60 |
| Nov 1, 2026 | 55 |
| Oct 31, 2026 | 47 |
| Oct 30, 2026 | 43 |
| Oct 29, 2026 | 33 |
| Oct 28, 2026 | 26 |
| Oct 27, 2026 | 25 |
| Oct 26, 2026 | 17 |
| Oct 25, 2026 | 11 |
| Oct 24, 2026 | 16 |
| Oct 23, 2026 | 13 |
| Oct 22, 2026 | 17 |
| Oct 21, 2026 | 28 |
| Oct 20, 2026 | 25 |
| Oct 19, 2026 | 24 |
| Oct 18, 2026 | 34 |
| Oct 17, 2026 | 31 |
| Oct 16, 2026 | 31 |
| Oct 15, 2026 | 28 |
| Oct 14, 2026 | 23 |
| Oct 13, 2026 | 23 |
| Oct 12, 2026 | 22 |
| Oct 11, 2026 | 20 |
| Oct 10, 2026 | 21 |
| Oct 9, 2026 | 23 |
| Oct 8, 2026 | 23 |
| Oct 7, 2026 | 18 |
| Oct 6, 2026 | 18 |
| Oct 5, 2026 | 19 |
| Oct 4, 2026 | 12 |
| Oct 3, 2026 | 8 |
| Oct 2, 2026 | 18 |
| Oct 1, 2026 | 18 |
| Sep 30, 2026 | 17 |
| Sep 29, 2026 | 23 |
| Sep 28, 2026 | 21 |
| Sep 27, 2026 | 32 |
| Sep 26, 2026 | 38 |
| Sep 25, 2026 | 28 |
| Sep 24, 2026 | 29 |
| Sep 23, 2026 | 29 |
| Sep 22, 2026 | 29 |
| Sep 21, 2026 | 29 |
| Sep 20, 2026 | 25 |
| Sep 19, 2026 | 25 |
| Sep 18, 2026 | 32 |
| Sep 17, 2026 | 38 |
| Sep 16, 2026 | 40 |
| Sep 15, 2026 | 34 |
| Sep 14, 2026 | 36 |
| Sep 13, 2026 | 32 |
| Sep 12, 2026 | 28 |
| Sep 11, 2026 | 26 |
| Sep 10, 2026 | 21 |
| Sep 9, 2026 | 20 |
| Sep 8, 2026 | 23 |
| Sep 7, 2026 | 25 |
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/611765581-rbac)<a href="https://payloaddirectory.dev/plugins/611765581-rbac"><img src="https://payloaddirectory.dev/badge/611765581-rbac.svg" alt="Payload Directory"></a>README
Easy to use Role based access for your Payload cms.
Main features:
With yarn:
yarn add payload-rbac
With npm:
npm install payload-rbac
Add the plugin to your payload config to extend your auth collection:
import { buildConfig } from 'payload/config';
import rbac from 'payload-rbac';
export default buildConfig({
plugins: [
rbac({
collections: ['users'], // collections to enable rbac on, default: all auth collections
roles: ['reader', 'maintainer', 'admin'], // roles
}),
],
// The rest of your config goes here
});
All access control functions allow you to control who can access your data and allow you to add an optional filter. This documentation assumes that you are familiar with the Payload documentation on access control.
Anyone has access
import { allowAnonymous } from 'payload-rbac';
const unfilteredAccess = allowAnonymous();
const filteredAccess = allowAnonymous<Page>({ _status: { equals: 'published' } });
You can also use the filtered alias, which might make you code more readable if you're using allowAnonymous in combiniation with other access control functions.
import { filtered } from 'payload-rbac';
const filteredAccess = filtered<Page>({ _status: { equals: 'published' } });
Any has access to published documents
import { allowPublished } from 'payload-rbac';
const allPublishedAccess = allowPublished();
const filteredAccess = allowPublished<Page>({ author: { equals: 'Santa' } });
Any logged in user has access
import { allowAnyUser } from 'payload-rbac';
const unfilteredAccess = allowAnyUser();
const filteredAccess = allowAnyUser<Post>({ author: { equals: ({ req }) => req.user!.id } });
Only users with the given role have access
import { allowUserWithRole } from 'payload-rbac';
const unfilteredAccess = allowUserWithRole('admin');
const filteredAccess = allowUserWithRole<Media>('reader', { _status: { equals: 'published' } });
Only allow access if the node environment variable with the given key has the given value
import { allowEnvironmentValues } from 'payload-rbac';
const unfilteredAccess = allowEnvironmentValues('SERVICE_ENV', 'staging');
const filteredAccess = allowEnvironmentValues<Alert>('SERVICE_ENV', 'staging', { _status: { equals: 'published' } });
Blocks all requests. If used with payload-openapi or payload-swagger, endpoints with this access control function are excluded from documentation.
import { blockAll } from 'payload-rbac';
const access = blockAll();
All payload-rbac access functions accept an optional where parameter. If a where paremeter is provided it is used as a query if access is granted. See payload documentation for more information queries.
As filter you can use a payload Where query, but you can also use functions as operands, that receive the AccessArgs as input.
import { Access } from 'payload';
import { filtered } from 'payload-rbac';
const access: Access = filtered<Page>({
or: [
{ _status: { equals: 'published' } }, // normal where
{ author: { equals: ({ req }) => req.user?.id || '#not-an-author#' } }, // active where
],
});
To get the most out of the typesystem, it is recommended to use the generic type parameter on the access control function to specify the collection you're using it on (Page in the example above). When you specify the collection the typesystem will be able to check that all paths are correct and your operands are of the correct type and it will be able to provide you autocomplete suggestions.
The composite access control functions allow you to easily combine access control functions, both the functions of payload-rbac as well as your own access control functions.
Allows access if at least one of the given control functions grants access. If all of the matching control functions return a query, those queries are combined with and or statement.
import { allowPublished, allowUserWithRole, requireOne } from 'payload-rbac';
// Anyone has access to published documents, but only editors can see draft documents
const requireOne(allowPublished(), allowUserWithRole('editor'));
Allows access if all of the given control functions grants access. If one or more of the access control functions return a query, those queries are combined with and and statement.
import { allowPublished, allowAnyUser, requireAll } from 'payload-rbac';
// User needs to login to see the published documents (and cannot see draft documents)
const requireAll(allowPublished(), allowAnyUser());
Composites can be nested:
import { allowPublished, allowAnyUser, allowUserWithRole, requireAll, requireOne } from 'payload-rbac';
const compositeAccess = requireOne(
requireAll(allowPublished(), allowAnyUser()), // any logged in user can access published documents
allowUserWithRole('editor'), // editors can access all documents
);
See changelog
create api docs
CLI that generates OpenAPI 3 documentation for a Payload CMS project
4348/wk143v1
payload simple rbac
Priority-ordered role-based access control for Payload collections, globals and fields
4227/wk40v1
payload default roles
Apply default role-based access permissions to every collection in one plugin call
2722/wk9v1
multi tenant
Manage multiple tenants and tenant-scoped content from a single Payload admin panel
100165.4k/wk46.1kv3 v4
payload plugin sharing
Share records with users and organizations through groups with Owner, Manager and Viewer levels
76425/wk0v3
payload plugin positions
Scoped, dated position grants for users on a site, organization or project, with host-defined types and an audit trail
76382/wk0v3