zealamic

payload plugin rbac

by zealamic
Roles & permissions
v3
^3.84.1
MIT

Overview

Summary generated from the README

Adds role-based access control to Payload v3 using permissions stored in the database as feature and action pairs, assigned to roles. It registers five RBAC collections, augments the users collection, and provides access helpers such as getPermissionAccess to enforce rules on app collections. Requires Payload 3.84.1 or later and a database migration after setup.

Features

  • Five RBAC collections for features, actions, permissions, roles and a join table
  • Multi-role users with the union of enabled grants
  • Data scope of own, hierarchy or all for row-level access
  • targetCollections option adds a hidden ownership field and create hook
  • Permission matrix UI on role edit screens with drag-and-drop reordering
  • Plugin translations merged into Payload i18n, plus custom matrix component support

Use cases

  • Restrict who can create, read, update or delete posts based on assigned roles
  • Limit editors to documents they created while managers see their team's content
  • Let admins edit role permissions in the Admin panel without redeploying code

From the author

A plugin for Payload CMS to manage authentication and authorization

Installation

npm i @zealamic/payload-plugin-rbac

10

Stars

1

Forks

0

Open Issues

5 months ago

Last Updated

74

Weekly Downloads

v1.3.0

npm Version

478.3 KB

Unpacked Size

0

Dependencies

GitHub stars

10+3 since Sep 7

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 202610
Dec 5, 202610
Dec 4, 202610
Dec 3, 202610
Dec 2, 202610
Dec 1, 202610
Nov 30, 202610
Nov 29, 202610
Nov 28, 202610
Nov 27, 202610
Nov 26, 202610
Nov 25, 202610
Nov 24, 202610
Nov 23, 202610
Nov 22, 202610
Nov 21, 202610
Nov 20, 202610
Nov 19, 202610
Nov 18, 202610
Nov 17, 202610
Nov 16, 202610
Nov 15, 202610
Nov 14, 202610
Nov 13, 202610
Nov 12, 202610
Nov 11, 202610
Nov 10, 202610
Nov 9, 202610
Nov 8, 202610
Nov 7, 202610
Nov 6, 202610
Nov 5, 202610
Nov 4, 202610
Nov 3, 202610
Nov 2, 202610
Nov 1, 202610
Oct 31, 202610
Oct 30, 202610
Oct 29, 202610
Oct 28, 202610
Oct 27, 202610
Oct 26, 202610
Oct 25, 202610
Oct 24, 202610
Oct 23, 202610
Oct 22, 202610
Oct 21, 202610
Oct 20, 202610
Oct 19, 202610
Oct 18, 202610
Oct 17, 202610
Oct 16, 202610
Oct 15, 202610
Oct 14, 202610
Oct 13, 202610
Oct 12, 202610
Oct 11, 202610
Oct 10, 202610
Oct 9, 202610
Oct 8, 202610
Oct 7, 202610
Oct 6, 202610
Oct 5, 202610
Oct 4, 20269
Oct 3, 20269
Oct 2, 20269
Oct 1, 20269
Sep 30, 20269
Sep 29, 20269
Sep 28, 20269
Sep 27, 20269
Sep 26, 20269
Sep 25, 20269
Sep 24, 20269
Sep 23, 20269
Sep 22, 20269
Sep 21, 20269
Sep 20, 20269
Sep 19, 20269
Sep 18, 20269
Sep 17, 20269
Sep 16, 20269
Sep 15, 20269
Sep 14, 20269
Sep 13, 20268
Sep 12, 20268
Sep 11, 20268
Sep 10, 20268
Sep 9, 20267
Sep 8, 20267
Sep 7, 20267
npm weekly downloads

72+49 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 202672
Dec 5, 202656
Dec 4, 202645
Dec 3, 202640
Dec 2, 202658
Dec 1, 202665
Nov 30, 202661
Nov 29, 202669
Nov 28, 202666
Nov 27, 202682
Nov 26, 202686
Nov 25, 202673
Nov 24, 202675
Nov 23, 202675
Nov 22, 202663
Nov 21, 202660
Nov 20, 202638
Nov 19, 202637
Nov 18, 202629
Nov 17, 202621
Nov 16, 202617
Nov 15, 202616
Nov 14, 202619
Nov 13, 202625
Nov 12, 202624
Nov 11, 202643
Nov 10, 202653
Nov 9, 202653
Nov 8, 202659
Nov 7, 202658
Nov 6, 202658
Nov 5, 202658
Nov 4, 202642
Nov 3, 202636
Nov 2, 202635
Nov 1, 202632
Oct 31, 202640
Oct 30, 202640
Oct 29, 202634
Oct 28, 202631
Oct 27, 202627
Oct 26, 202628
Oct 25, 202627
Oct 24, 202626
Oct 23, 202619
Oct 22, 202633
Oct 21, 202650
Oct 20, 202667
Oct 19, 202681
Oct 18, 202695
Oct 17, 2026100
Oct 16, 2026108
Oct 15, 2026147
Oct 14, 2026138
Oct 13, 2026123
Oct 12, 2026119
Oct 11, 2026107
Oct 10, 202694
Oct 9, 2026166
Oct 8, 2026455
Oct 7, 2026450
Oct 6, 2026447
Oct 5, 2026439
Oct 4, 2026438
Oct 3, 2026446
Oct 2, 2026366
Oct 1, 202639
Sep 30, 202643
Sep 29, 202648
Sep 28, 202645
Sep 27, 202647
Sep 26, 202641
Sep 25, 202655
Sep 24, 202643
Sep 23, 202642
Sep 22, 202643
Sep 21, 202667
Sep 20, 202678
Sep 19, 202676
Sep 18, 202670
Sep 17, 202673
Sep 16, 202670
Sep 15, 202667
Sep 14, 202643
Sep 13, 202628
Sep 12, 202638
Sep 11, 202635
Sep 10, 202630
Sep 9, 202629
Sep 8, 202621
Sep 7, 202623

Each point is npm's rolling 7-day download count.

Health Score

58/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1251146173-root.svg)](https://payloaddirectory.dev/plugins/1251146173-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1251146173-root"><img src="https://payloaddirectory.dev/badge/1251146173-root.svg" alt="Payload Directory"></a>
Updated Jul 3, 2026Created May 27, 2026Published Jul 3, 2026

README

@zealamic/payload-plugin-rbac

Centralized role-based access control (RBAC) for Payload CMS v3 (payload ^3.84.1). Not compatible with Payload 2.x.

Payload Auth RBAC Plugin

Permissions live in the database (feature + action), are assigned to roles, and enforced via reusable access helpers — editable in Admin without redeploying policy code.

Row-level access (dataScope): list collection slugs in targetCollections for auto ownership field + create hook, then wire getPermissionAccess. → COLLECTIONS — targetCollections · manual setup → UTILS


Documentation

GuideRead when you need to…
COLLECTIONSPlugin collections, users augmentation, dataScope, permission matrix, field/access overrides
UTILSgetPermissionAccess, data-scope filters, field merge helpers
TRANSLATIONSAdmin labels, select options, matrix UI strings (en, vi, …)
CUSTOM_COMPONENTSCustom matrix checkboxes / search input (client field component)

Typical flow: install → register plugin with targetCollections (COLLECTIONS) → run migration → seed RBAC data (COLLECTIONS) → add getPermissionAccess on app collections (UTILS) → translate Admin UI (TRANSLATIONS).

Demos in this repo: dev/rbac.ts, dev/collections/posts.ts, dev/components/role-permission-matrix-field.tsx.


Key features

  • Five RBAC collections — features, actions, permissions, roles, join table (details)
  • Multi-role users — union of enabled grants across assigned roles
  • Granular permissions — any featureCode + actionCode pair (helpers)
  • Data scope — own / hierarchy / all; use targetCollections for ownership field + hook, or add manually (UTILS)
  • targetCollections — auto-add hidden ownership field + create hook on app collections (COLLECTIONS)
  • Auth users slug — config.admin.user (default users) for hierarchy + options.usersCollectionSlug
  • Permission matrix — role update UI; syncs draft → roles-permissions on save
  • Reorder drawers — drag-and-drop sortOrder for permission features and actions on each collection list view
  • Custom matrix UI — optional client field component + render props (CUSTOM_COMPONENTS)
  • TypeScript — typed plugin config and exported helpers/types from the main package
  • i18n — plugin translations merged into Payload i18n (guide)

Installation

npm install @zealamic/payload-plugin-rbac
# or: yarn add / pnpm add @zealamic/payload-plugin-rbac

Quick start

1. Register the plugin

import { payloadPluginRBAC } from "@zealamic/payload-plugin-rbac";

export default buildConfig({
  plugins: [
    payloadPluginRBAC({
      autoModifyUsersCollection: true, // roles, isSuperAdmin, parent, default user access
      targetCollections: ["posts"], // ownership field + create hook — see step 4
      // collections: { ... }   → https://github.com/zealamic/payload-plugin-rbac/blob/main/docs/COLLECTIONS.md
      // translations: { ... } → https://github.com/zealamic/payload-plugin-rbac/blob/main/docs/TRANSLATIONS.md
      // components: { rolePermissionMatrixField: "..." } → custom matrix Field (client module)
    }),
  ],
});

2. Migration

After adding the plugin (and especially after changing targetCollections), update your database schema:

yarn payload migrate:create
yarn payload migrate

(npm run / pnpm equivalents work too.)

Run migrate:create when new fields are added to collections (e.g. first time you list a slug in targetCollections). Then migrate to apply pending migrations.

Bootstrap a super admin: RBAC collections are restricted to super admins by default. Set isSuperAdmin: true on at least one user (via seed script, Local API, or direct database update) before you can manage roles, permissions, and the permission matrix in Admin.

→ COLLECTIONS — Bootstrap super admin

3. Seed RBAC data (Admin or script)

  1. permission-features — e.g. posts, users (code = featureCode in access helpers); use Reorder on the list view to set row order in the matrix
  2. permission-actions — e.g. create, read, update, delete (main / sub types); use Reorder to set main column and sub-action order
  3. permissions — one row per feature + action pair (status: active)
  4. roles — set dataScope; open update screen, configure matrix → Save
  5. users — assign roles; bootstrap isSuperAdmin via seed/API

→ Full reference: COLLECTIONS

4. Protect app collections

Recommended: list slugs in targetCollections — the plugin adds a hidden ownership field (createdBy text by default) and a create hook. You only wire getPermissionAccess on the collection. Full options → COLLECTIONS — targetCollections.

// payload.config.ts
payloadPluginRBAC({
  targetCollections: ["posts"],
});

// collections/posts.ts — no manual createdBy field or hook needed
import type { CollectionConfig } from "payload";
import { getPermissionAccess } from "@zealamic/payload-plugin-rbac";

export const Posts: CollectionConfig = {
  slug: "posts",
  access: {
    read: getPermissionAccess({ featureCode: "posts", actionCode: "read", options: {} }),
    create: getPermissionAccess({ featureCode: "posts", actionCode: "create" }),
    update: getPermissionAccess({ featureCode: "posts", actionCode: "update", mode: "modify" }),
    delete: getPermissionAccess({ featureCode: "posts", actionCode: "delete", mode: "modify" }),
  },
  fields: [{ name: "title", type: "text", required: true }],
};

After adding or changing targetCollections, run yarn payload migrate:create then yarn payload migrate.

Manual setup (visible fields, custom layout, or full control): add ownership field + create hook yourself → UTILS — Ownership field · relationship demo: dev/collections/posts.ts

Access order: no user → deny · super admin → allow · else → matrix permission (+ scope when options / mode: "modify").


Reorder overview (features & actions)

List views for permission-features and permission-actions include a Reorder drawer to set sortOrder (hidden on edit forms). Order drives the role permission matrix: features → rows, main actions → columns, sub actions → checkbox order under each row.

Sorted matrix

StepAction
FeaturesPermission Features → Reorder → drag → Save order
ActionsPermission Actions → Reorder → pick Main or Sub → drag → Save order

Reorder permission features Reorder permission actions

API: POST /api/permission-features/reorder · POST /api/permission-actions/reorder — body { "sortedItems": [{ "id": "…", "sortOrder": 0 }] }. Requires update access (super admin by default). Details → COLLECTIONS · labels → TRANSLATIONS — Reorder drawers.


Plugin options

OptionDefaultDescription
disabledfalseSkip runtime i18n/onInit wiring; collections still register in schema
autoModifyUsersCollectiontrueAdd RBAC fields, parent-path hooks, and default access on the auth users collection
targetCollections—Auto ownership field + create hook on listed app collections → COLLECTIONS
translations—Admin + matrix i18n → TRANSLATIONS
collections—Per-collection fields / access / admin overrides → COLLECTIONS
components.rolePermissionMatrixFielddefault client exportImport-map path to a custom matrix Field component (client module)

Types import from the main entry:

import type {
  RBACTranslations,
  PayloadPluginRBACConfig,
  TargetCollection,
} from "@zealamic/payload-plugin-rbac";

Exported helpers (summary)

Full reference: UTILS

FunctionPurpose
getPermissionAccessUnified access: permission-only, read Where, or modify per-document
targetCollections (plugin config)Quick ownership field + hook — COLLECTIONS
getCreatedByRelationshipField / createCreatedByOnCreateBeforeChangeHookManual ownership field + hook → UTILS
resolveUsersCollectionSlugSame admin.user → slug resolution as the plugin
getSuperAdminAccessSuper admin only (default on RBAC collections)
getAuthenticatedOrSuperAdminAccessOwner or super admin
canAccessDocumentByDataScopeLow-level single-document RBAC + scope check
resolveEffectiveDataScope / getHierarchyVisibleUserIdsScope resolution
getDataScopeReadWhere / mergeDataScopeWhereQuery filters
getMergedFieldAffectingData / getArrayOfMergedFieldAffectingDataField merge for overrides

Constants: CONSTANTS.ROLE.DATA_SCOPE, CONSTANTS.PERMISSION_ACTION.TYPE, etc.


Package exports

ImportContents
@zealamic/payload-plugin-rbacpayloadPluginRBAC, utils, constants, TypeScript types
@zealamic/payload-plugin-rbac/clientRolePermissionMatrixClient, PermissionActionReorderClient, PermissionFeatureReorderClient, createRolePermissionMatrixClient, and related types

Images from demo

demo-1

Reorder screenshots: Reorder overview above.


License

MIT


If this plugin helps your team ship safer access control with less friction, thank you for giving it a place in your stack.

Similar plugins