UPDOT

payload access plugin

by UPDOT
Roles & permissions
v3
^3.90.0
MIT

Overview

Summary generated from the README

Adds a roles collection and a roles field on users so admins can define who may read, create, update, delete and publish each collection and global, and which fields are hidden or read-only, without a deploy. It wraps access functions so the final result is your own rule combined with the role, and adds an Access matrix screen at the admin route. Requires Payload 3.90 or later, and the import map must be regenerated.

Features

  • Roles stored as records; users can hold several and permissions add up
  • Access matrix screen with a new-role wizard and a role edit grid
  • Collection, global and field-level enforcement that only narrows existing access rules
  • Code-level locks, super admin and manage-roles functions
  • Own scope via an ownership field, plus custom actions checked with can()
  • Endpoints returning the current user's permissions and the matrix schema

Use cases

  • Let non-developer admins create and adjust editor roles and permissions without redeploying
  • Hide or make read-only sensitive fields for specific roles
  • Restrict editors to updating only documents they own

From the author

Editable roles and an access matrix for Payload CMS

Installation

npm i payload-access-plugin

0

Stars

0

Forks

0

Open Issues

Today

Last Updated

0

Weekly Downloads

v

npm Version

Dependencies

GitHub stars

00 since Nov 29

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 20260
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
npm weekly downloads

Trends appear after 7 days of data. Daily snapshots have not started yet.

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

Health Score

35/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/1483093820-root.svg)](https://payloaddirectory.dev/plugins/1483093820-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1483093820-root"><img src="https://payloaddirectory.dev/badge/1483093820-root.svg" alt="Payload Directory"></a>
Updated Dec 5, 2026Created Dec 4, 2026

README

payload-access-plugin

Editable roles and an access matrix for Payload 3. Admins create roles and decide who can read, create, update, delete and publish each collection and global, and which fields are hidden or read-only, without a deploy. The app sets the guardrails in code.

  • Roles are records. A user can hold several, and their permissions add up.
  • An Access matrix screen in the admin panel, with a new-role wizard and a role edit grid.
  • Enforcement on collections, globals and fields. The plugin can only narrow what your own access rules allow.
  • Locks, super admins and who may manage roles are set in code.
  • GET /api/access-plugin/me and GET /api/access-plugin/schema endpoints.

Install

npm install payload-access-plugin
# or
pnpm add payload-access-plugin
# or
bun add payload-access-plugin

Peer dependency: payload ^3.90.0.

Quick start

import { buildConfig } from 'payload'
import { accessPlugin } from 'payload-access-plugin'

export default buildConfig({
  // collections: [Users, Posts, ...]
  plugins: [
    accessPlugin({
      roles: { seed: [{ name: 'Admin', slug: 'admin', locked: true, permissions: {} }] },
      superAdmin: (user) => user?.roles?.some((role) => role?.slug === 'admin') ?? false,
    }),
  ],
})

Then run payload generate:importmap so the admin panel finds the plugin's components. The plugin adds a roles collection and a roles field on your users collection, and an Access screen at /admin/access.

Create the first admin user and give them the admin role right away (see the first-user note under Limitations and notes).

Options

Every option is optional. All are passed to accessPlugin(options).

OptionTypeDefaultMeaning
enabledbooleantrueWhen false, the roles collection and the users field stay, and so do the role guardrails and the manageRoles gate on the roles collection. Only the collection, global and field restrictions, the Access screen and the endpoints are off.
usersCollectionSlug | CollectionSlug[]the admin user collection (admin.user)Auth collections that get a roles field. Throws if a slug is not in the config.
roles.slugstring'roles'Slug of the roles collection.
roles.overrides(collection: CollectionConfig) => CollectionConfignoneAdjust the roles collection before it is registered.
roles.seedRoleSeed[][]Roles created on init when no role with that slug exists. Existing roles are never overwritten.
govern.collectionstrue | CollectionSlug[] | { include?: CollectionSlug[]; exclude?: CollectionSlug[] }every collection except the roles collection and payload-* collectionsCollections that appear in the matrix and are enforced.
govern.globalstrue | GlobalSlug[] | { include?: GlobalSlug[]; exclude?: GlobalSlug[] }every global except payload-* globalsGlobals that appear in the matrix and are enforced.
govern.fieldsboolean | Record<string, string[]>every named fieldField-level rows. false turns them off. A record lists dotted field paths per collection or global slug.
actions{ name: string; label: string; appliesTo?: string[] }[][]App-defined actions shown in the matrix. appliesTo lists governed slugs and defaults to all. Check them with can().
ownership{ field: string } | Record<CollectionSlug, string>noneEnables the own scope. One field name for every governed collection, or a field name per collection.
superAdmin(user) => boolean() => falseUsers for whom this returns true bypass the matrix. They never bypass the app's own access rules.
manageRoles(user) => booleanthe superAdmin functionWho may edit roles, assign them and see the matrix.
locksLock[][]Code-level values the matrix shows and cannot change. Locks win over role data.
defaultRolesstring[][]Role slugs given to a new user when none are set.
cache.ttlSecondsnumber30How long role lookups stay in the process cache.
admin.groupstringnone (top-level link)Nav group for the Access link.
admin.pathstring'/access'Route of the matrix screen under the admin route.
admin.labelstringthe translated "Access" labelNav link label.
i18nPartial<Translations>{}Override any string the screens show. English is the default.

manageRoles and superAdmin receive the user with its roles populated, so you can compare role slugs. Both run on every request.

Lock is { roles: '*' | string[]; target: string; action: string; value: 'allow' | 'deny' | 'own' }. target is a collection or global slug, or '*'. Locks apply in array order and later locks override earlier ones for the same cell.

RoleSeed is { name: string; slug: string; permissions: RolePermissions; description?: string; locked?: boolean }. RolePermissions is { collections?, globals?, fields?, custom? }. For example:

{
  collections: { posts: { read: 'all', update: 'own' } },
  globals: { settings: { read: 'all' } },
  fields: { posts: { internalNotes: 'hidden' } },
}

Scopes are 'all', 'own' or 'none'. Field rules are 'hidden' or 'readOnly'. Built-in actions:

  • Collections: read, create, update, delete. readVersions when versions are on. publish when drafts are on.
  • Globals: read, update. readVersions when versions are on. publish when drafts are on.

Exports: accessPlugin, can(req, target, action), getPermissions(req) and the types AccessPluginOptions, CustomAction, Lock, RoleSeed and Translations from payload-access-plugin. The admin components come from payload-access-plugin/client and payload-access-plugin/rsc.

See docs/recipes.md for worked examples.

Security model

  • Final access is your rule AND the role. For each governed collection and global, every access function is wrapped: final = appAccess AND roleAccess. Booleans and Where results combine (both wheres are joined with and). A role grants only what your own rules already allow, never more. Missing app access counts as Payload's default (signed in).
  • Roles add up. The most permissive scope wins (all over own over none). A field is hidden or read-only only if every role says so.
  • Locks win. A lock overrides what any role says for that cell, and the matrix shows the cell as locked.
  • Super admins bypass roles, not your code. superAdmin skips the matrix. The app's own access functions still apply.
  • Permissions are never in the JWT. They are read from the role records on each request (once per request, plus a short process cache that the roles collection invalidates on change), so a role change applies on the next request without signing out.
  • Guardrails in the plugin itself:
    • Locked roles refuse update and delete.
    • A role's slug is fixed once created.
    • A role that is still assigned to users cannot be deleted.
    • A user without manageRoles cannot change anyone's roles, their own included.
    • The last user holding a super-admin role cannot lose it and cannot be deleted.
    • Bulk updates and deletes go through the same checks.
    • A user who has manageRoles but is not a super admin cannot make anyone a super admin, themselves included. A roles change that newly gives a user a super-admin role is refused with a 403 ("Only a super admin can grant a super-admin role."). Calls without a signed-in user and calls with overrideAccess (seeds, the first user) are trusted.
  • A role that can update users can change their accounts. A role granting update on a governed users collection lets its holders change those users' accounts, credentials included.

Screens

  • Access matrix at /admin/access (change it with admin.path). Rows are collection and action, columns are roles. Click a cell to cycle none, all and own (own only where ownership is configured). Locked cells show why they are locked. Filter by group or role, or show only differences. Changes save together after a summary of what will change.
  • New-role wizard. The "+" button on the matrix opens a drawer with five steps: Name, Start from (blank, copy a role, or read-only), Permissions, Fields and globals, Review. The new role appears as a filled column.
  • Role edit grid. The edit view of a role in the roles collection shows that role's permissions as a grid.

The nav link, and the schema it reads, are only for users who pass manageRoles. Roles keep their normal list and edit views, and the roles collection is versioned, so you can audit changes.

Endpoints

Both are mounted under Payload's API route (/api by default). Neither exists when enabled is false.

GET /api/access-plugin/me

The signed-in user's merged permissions, for front ends.

  • 200:

    {
      "roles": ["editor"],
      "superAdmin": false,
      "collections": { "posts": { "read": "all", "update": "own", "publish": "none" } },
      "globals": { "settings": { "read": "all", "update": "none" } },
      "fields": { "posts": { "internalNotes": "hidden" } },
      "custom": []
    }
    

    Scopes are all, own or none. fields lists only fields with a rule and is empty for super admins. custom is the role's free-form custom entries.

  • 401: { "errors": [{ "message": "You must be signed in." }] }

GET /api/access-plugin/schema

What the matrix shows. Only for users who pass manageRoles.

  • 200:

    {
      "rolesSlug": "roles",
      "targets": {
        "posts": {
          "kind": "collection",
          "label": "Posts",
          "group": "Content",
          "actions": [{ "name": "read", "label": "Read" }],
          "fields": [{ "path": "title", "label": "Title" }]
        }
      },
      "customActions": [{ "name": "export", "label": "Export" }],
      "locks": [],
      "ownership": ["posts"]
    }
    

    ownership lists the slugs that have an owner field. group is present when the collection or global has an admin.group.

  • 401: not signed in (same body as above).

  • 403: { "errors": [{ "message": "You are not allowed to manage roles." }] }

Payload's own /api/access keeps working and reflects the wrapped rules.

Limitations and notes

  • The users collection is governed like any other. Users without a role that grants them read and update on the users collection cannot read or edit their own account. Either exclude auth collections from govern.collections (for example { exclude: ['users'] }) or give every role a users permission.
  • First-user window. While no user exists, the first created user may be given roles, and any users collection that is publicly creatable can do the same until then. Seed a super-admin role and create the first admin immediately.
  • The role cache is per process. Other instances see a role change after cache.ttlSeconds (default 30 seconds). The instance that saves the role sees it at once.
  • Concurrent demotions. Two truly concurrent single-user demotions of the last two super admins are not prevented. Each check sees the other still holding the role.
  • can() reports the role scope only. It does not run your collection's own access rules. Use it for custom actions and UI hints, not as the only check on a document.
  • Existing owner field. If a collection already has a field named like the ownership field, the plugin does not manage it and clients can set it.
  • Empty roles on create. An empty roles array on create counts as no roles and gets defaultRoles.
  • Nav groups. An admin.group equal to an existing nav group label renders a second group with the same name.

Payload compatibility

payload-access-pluginPayloadDatabase adapters tested
0.1.x^3.90.0SQLite, Postgres, MongoDB

CI runs the integration tests on Payload 3.90.0 and 3.94.2 against all three adapters. Payload 4 is not supported yet.

Payload 3.90.0 is the minimum because earlier 3.x releases do not pass the incoming data to collection update access on bulk (where-based) updates, so the plugin could not enforce the publish permission there, and before 3.88.0 a user could sort by a field their role hides. Node ^22.23.5 || ^24.22.3 || >=26.13.1.

Contributing

Use bun.

bun install
bun run dev              # dev app with the plugin
bun run test:int         # integration tests (vitest)
bun run test:e2e         # Playwright, including axe checks
bun run lint
bun run typecheck
bun run build

TEST_DB selects the database for the integration tests and the dev app:

  • sqlite (default): file dev/test.db, recreated for every test run.
  • postgres: uses DATABASE_URL.
  • mongodb: starts an in-memory replica set.

For example, TEST_DB=mongodb bun run test:int. The e2e tests run with TEST_DB=sqlite after bun run generate:importmap.

Add a changeset for any user-facing change with bun run changeset. Releases are cut by the release workflow when the version pull request is merged.

License

MIT

Similar plugins