salemaljebaly

payload plugin rbac ui

by salemaljebaly
Roles & permissions
v3
^3.76.1
MIT

Overview

Summary generated from the README

Injects a grouped checkbox permissions field into your Roles collection and validates saved values against an allow-list built from your collections and globals. Permission strings such as Create:Post are generated automatically, and manual groups can be merged in. You still add the access checks to each collection yourself, and the import map must be regenerated after install.

Features

  • Grouped checkbox permissions matrix injected into the Roles collection
  • Auto-discovers collections and globals to build the permission allow-list
  • Validates saved permissions against the allowed strings
  • Hybrid mode merges manual permission groups with auto-discovered ones
  • Configurable actions, permission formatting and group labels
  • Callback to modify the final roles collection config

Use cases

  • Give admins a visual way to assign per-collection permissions to roles
  • Gate collection and global access by role-based permission strings
  • Define custom permissions like Publish:Post alongside generated CRUD ones

From the author

Reusable RBAC permissions UI and helpers for Payload CMS

Installation

npm i @salemaljebaly/payload-plugin-rbac-ui

1

Stars

0

Forks

4

Open Issues

6 months ago

Last Updated

194

Weekly Downloads

v0.5.0

npm Version

60.6 KB

Unpacked Size

0

Dependencies

GitHub stars

10 since Sep 6

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

183+174 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 2026183
Dec 4, 2026150
Dec 3, 2026121
Dec 2, 202694
Dec 1, 2026118
Nov 30, 2026121
Nov 29, 202689
Nov 28, 202665
Nov 27, 202653
Nov 26, 202671
Nov 25, 2026103
Nov 24, 202685
Nov 23, 202687
Nov 22, 2026180
Nov 21, 2026348
Nov 20, 2026349
Nov 19, 2026331
Nov 18, 2026315
Nov 17, 2026309
Nov 16, 2026304
Nov 15, 2026206
Nov 14, 202643
Nov 13, 202641
Nov 12, 202641
Nov 11, 202627
Nov 10, 202634
Nov 9, 202646
Nov 8, 202654
Nov 7, 202655
Nov 6, 202658
Nov 5, 202661
Nov 4, 202664
Nov 3, 202657
Nov 2, 202646
Nov 1, 202654
Oct 31, 202658
Oct 30, 202657
Oct 29, 202653
Oct 28, 202643
Oct 27, 202644
Oct 26, 202638
Oct 25, 202629
Oct 24, 202618
Oct 23, 202615
Oct 22, 202617
Oct 21, 202630
Oct 20, 202631
Oct 19, 202633
Oct 18, 202625
Oct 17, 202627
Oct 16, 202636
Oct 15, 202639
Oct 14, 202633
Oct 13, 202631
Oct 12, 202635
Oct 11, 202635
Oct 10, 202633
Oct 9, 202624
Oct 8, 202619
Oct 7, 202612
Oct 6, 202611
Oct 5, 20262
Oct 4, 20261
Oct 3, 20260
Oct 2, 20260
Oct 1, 20260
Sep 30, 20260
Sep 29, 20260
Sep 28, 20260
Sep 27, 20260
Sep 26, 20263
Sep 25, 20263
Sep 24, 20263
Sep 23, 20263
Sep 22, 20264
Sep 21, 202612
Sep 20, 202612
Sep 19, 20269
Sep 18, 202610
Sep 17, 202610
Sep 16, 202611
Sep 15, 202611
Sep 14, 20263
Sep 13, 20267
Sep 12, 20268
Sep 11, 20267
Sep 10, 20268
Sep 9, 20268
Sep 8, 20268
Sep 7, 20269
Sep 6, 20269

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

Health Score

43/100Fair

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/1158141331-root.svg)](https://payloaddirectory.dev/plugins/1158141331-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1158141331-root"><img src="https://payloaddirectory.dev/badge/1158141331-root.svg" alt="Payload Directory"></a>
Updated Jun 8, 2026Created Feb 14, 2026Published Mar 31, 2026

README

@salemaljebaly/payload-plugin-rbac-ui

npm version npm downloads license

RBAC permissions matrix UI for Payload CMS. Injects a grouped checkbox UI into your Roles collection and validates saved permissions against an auto-discovered allow-list.

Permissions Matrix UI

Install

pnpm add @salemaljebaly/payload-plugin-rbac-ui
# or
npm install @salemaljebaly/payload-plugin-rbac-ui

Setup

1. Access helpers

Create these helpers first — they are used in the collections below.

// src/access/index.ts
import type { Access } from 'payload'

/** Check if user is a super admin (bypasses all permission checks). */
export function isSuperAdmin(user: any): boolean {
  return user?.superAdmin === true
}

/** Check if user has a specific permission in any of their roles. */
export function hasPermission(user: any, permission: string): boolean {
  if (!user?.roles) return false
  const roles = Array.isArray(user.roles) ? user.roles : [user.roles]
  return roles.some((role: any) => {
    const permissions = typeof role === 'object' ? role?.permissions : null
    return Array.isArray(permissions) && permissions.includes(permission)
  })
}

/** Use in collection access — super admins always pass, others need the permission. */
export const checkPermission =
  (permission: string): Access =>
  ({ req: { user } }) =>
    isSuperAdmin(user) || hasPermission(user, permission)

2. Users collection

Add a superAdmin flag and a roles relationship to your Users collection:

// src/collections/Users.ts
fields: [
  {
    name: 'superAdmin',
    type: 'checkbox',
    defaultValue: false,
    access: {
      // Only super admins can grant super admin access
      update: ({ req: { user } }) => isSuperAdmin(user),
    },
    admin: { description: 'Grants full access, bypasses all permission checks.' },
  },
  {
    name: 'roles',
    type: 'relationship',
    relationTo: 'roles',
    hasMany: true,
    saveToJWT: true, // Required — without this, hasPermission() always returns false
  },
]

3. Roles collection

// src/collections/Roles.ts
import type { CollectionConfig } from 'payload'
import { isSuperAdmin } from '../access'

export const Roles: CollectionConfig = {
  slug: 'roles',
  admin: { useAsTitle: 'name' },
  access: {
    read:   ({ req: { user } }) => isSuperAdmin(user),
    create: ({ req: { user } }) => isSuperAdmin(user),
    update: ({ req: { user } }) => isSuperAdmin(user),
    delete: ({ req: { user } }) => isSuperAdmin(user),
  },
  fields: [
    { name: 'name', type: 'text', required: true, unique: true },
    { name: 'description', type: 'textarea' },
    // 'permissions' field is injected automatically by the plugin
  ],
}

4. Add the plugin

// src/payload.config.ts
import { rbacUIPlugin } from '@salemaljebaly/payload-plugin-rbac-ui'

export default buildConfig({
  collections: [Users, Roles, Posts /* ... */],
  plugins: [
    rbacUIPlugin({
      rolesCollectionSlug: 'roles',
      autoDiscover: true,
    }),
  ],
})

5. Generate the import map

After adding the plugin, run this once so Payload registers the permissions UI component:

pnpm payload generate:importmap
# or: npx payload generate:importmap

Re-run this whenever you add or remove Payload plugins with custom UI.

6. Enforce permissions on your collections

The plugin does not protect your collections automatically. You must add checkPermission (or isSuperAdmin) to every collection you want to gate. Any collection without a custom access rule remains visible and accessible to all authenticated users.

Not sure what string to pass? Complete the first setup (step 7), then open any Role in the admin UI — all generated permission strings are listed there.

Apply to every collection — including Media:

// src/collections/Posts.ts
import { checkPermission } from '../access'

access: {
  create: checkPermission('Create:Post'),
  read:   checkPermission('Read:Post'),
  update: checkPermission('Update:Post'),
  delete: checkPermission('Delete:Post'),
}

7. First setup

No one has superAdmin: true yet, so no one can access the Roles collection. Bootstrap by adding a temporary seed route:

// src/app/seed/route.ts  — REMOVE IN PRODUCTION
import configPromise from '@payload-config'
import { getPayload } from 'payload'

export const GET = async () => {
  const payload = await getPayload({ config: configPromise })
  const { docs } = await payload.find({ collection: 'users', limit: 1, sort: 'createdAt' })
  if (!docs[0]) return Response.json({ error: 'Create an account first.' }, { status: 404 })
  await payload.update({
    collection: 'users',
    id: docs[0].id,
    data: { superAdmin: true } as any,
    overrideAccess: true,
  })
  return Response.json({ message: 'Done! Log out and back in.', email: docs[0].email })
}
  1. Start your dev server, create your account at /admin/create-first-user
  2. Visit http://localhost:3000/seed — your account is now superAdmin
  3. Log out and back in so the JWT refreshes
  4. Delete the seed route before deploying

The re-login step is required — the superAdmin flag is read from the JWT on each request.


Permission string format

TypeSlugGenerated strings
CollectionpostsCreate:Post, Read:Post, Update:Post, Delete:Post
CollectioncategoriesCreate:Category, Read:Category, …
GlobalsettingsRead:Global:Setting, Update:Global:Setting

Rule: slug → singularize → PascalCase. Open the Roles admin UI to see the exact strings for your app.

Hybrid mode (auto + custom)

rbacUIPlugin({
  autoDiscover: true,
  permissionGroups: [
    {
      label: 'Post',
      permissions: [
        { action: 'Publish', description: 'Publish posts', permission: 'Publish:Post' },
      ],
    },
  ],
})

Auto-discovered and manual groups with the same label are merged.

Options

OptionDefaultDescription
rolesCollectionSlug'roles'Slug of your roles collection
permissionsFieldName'permissions'Field name to inject/patch
permissionGroups[]Manual permission groups
autoDiscoverfalsetrue or config object (see below)
rolesFieldDescription—Description shown under the field
ensurePermissionsFieldtrueAuto-add field if missing. Set false to skip
customFieldPath—Override the React component path
onConfigureRolesCollection—Callback to modify the final collection config

autoDiscover options

OptionDefaultDescription
collectionstrueDiscover from collections
globalstrueDiscover from globals
collectionActions['Create','Read','Update','Delete']Actions per collection
globalActions['Read','Update']Actions per global
includeRolesCollectiontrueInclude the roles collection itself. Set false to exclude — permissions like Create:Role won't be in the allow-list, so don't use them in seed data
formatPermission(ctx)—ctx: { action: string, slug: string, source: 'collection' | 'global' } → string
formatGroupLabel(ctx)—ctx: { slug: string, source: 'collection' | 'global' } → string

Compatibility

  • Payload: ^3.76.1
  • React: ^19
  • Next.js: >=15.2.9 <15.3.0 || >=15.3.9 <15.4.0 || >=15.4.11 <15.5.0 || >=16.2.0-canary.10 <17.0.0

Development

pnpm install
pnpm build
pnpm typecheck
pnpm test

Contributing

  1. Fork and branch from main.
  2. Make focused changes with tests.
  3. Run pnpm build && pnpm typecheck && pnpm test.
  4. Open a PR with clear before/after context.

See CONTRIBUTING.md for details.

Releasing

pnpm version patch   # or minor / major
pnpm publish --access public
git tag -a vX.Y.Z -m "Release vX.Y.Z"
git push origin vX.Y.Z

Similar plugins