npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kurto/payload-access

v1.0.3

Published

Payload 3.0 Basic Access Control Utilities

Downloads

67

Readme

payload-access

A Role-Based Access Control (RBAC) plugin for Payload CMS with a 3-tier permission system.

Features

  • 3-Tier Role System: Developer, Admin, and Editor roles with hierarchical permissions
  • First User Protection: Automatically assigns the first user as a Developer
  • Developer Email Enforcement: Hardcode specific emails to always have Developer role
  • Granular Access Control: Prevents privilege escalation and unauthorized access
  • Helper Functions: Export isDeveloper, isAdmin, isEditor for use in your collections

Installation

pnpm add payload-access

Usage

Add the plugin to your Payload config:

import { payloadAccess } from 'payload-access'
import { buildConfig } from 'payload'

export default buildConfig({
  collections: [
    {
      slug: 'users',
      auth: true,
      fields: [
        // Your user fields
      ],
    },
  ],
  plugins: [
    payloadAccess({
      developerEmails: ['[email protected]', '[email protected]'],
    }),
  ],
})

Role Hierarchy

Developer

  • Full access to all users
  • Can create, read, update, and delete any user
  • Cannot be modified by Admins or Editors

Admin

  • Can create and manage users
  • Cannot modify or delete users with Developer role
  • Cannot grant Developer role to any user

Editor

  • Can only update their own profile
  • Cannot create, update, or delete other users

Configuration

Options

type PayloadAccessConfig = {
  developerEmails?: string[] // Array of emails that should always have Developer role
  disabled?: boolean // Disable the plugin
}

Example

payloadAccess({
  developerEmails: ['[email protected]', '[email protected]'],
})

Helper Functions

The plugin exports helper functions you can use in your own collections:

Basic Role Checks

import { isDeveloper, isAdmin, isEditor } from 'payload-access'

// Check individual roles
isDeveloper(user) // Returns true if user has developer role
isAdmin(user) // Returns true if user has admin role
isEditor(user) // Returns true if user has editor role

Advanced Helpers

import {
  hasElevatedAccess,
  hasMinimumRole,
  hasAnyRole,
  hasAllRoles,
  getUserRoles,
  canManageUser,
  isOwner,
  canEdit,
} from 'payload-access'

// Check for elevated access (developer OR admin)
hasElevatedAccess(user)

// Check role hierarchy (developer > admin > editor)
hasMinimumRole(user, 'admin') // True if developer or admin
hasMinimumRole(user, 'editor') // True if any role

// Check for specific role combinations
hasAnyRole(user, ['developer', 'admin']) // Has at least one
hasAllRoles(user, ['admin', 'editor']) // Has all specified

// Get all user roles as array
const roles = getUserRoles(user) // ['developer', 'admin']

// Check if user can manage another user
canManageUser(currentUser, targetUser) // Respects hierarchy

// Check document ownership
isOwner(user, documentUserId) // Compares user IDs

// Check edit permissions (owner OR elevated access)
canEdit(user, documentUserId)

Usage Examples

Simple access control:

{
  slug: 'posts',
  access: {
    create: ({ req: { user } }) => hasElevatedAccess(user),
    update: ({ req: { user } }) => {
      if (hasElevatedAccess(user)) return true
      return { author: { equals: user.id } }
    },
  },
}

Role-based field access:

{
  name: 'salary',
  type: 'number',
  access: {
    read: ({ req: { user }, doc }) => {
      return isOwner(user, doc.id) || hasMinimumRole(user, 'admin')
    },
    update: ({ req: { user } }) => hasMinimumRole(user, 'admin'),
  },
}

Complex permissions:

{
  slug: 'projects',
  access: {
    delete: ({ req: { user } }) => {
      // Only developers can delete, or admins for non-critical projects
      if (isDeveloper(user)) return true
      if (isAdmin(user)) {
        return { critical: { equals: false } }
      }
      return false
    },
  },
}

How It Works

First User Rule

When the first user is created (total user count === 0), they are automatically assigned the Developer role, regardless of what role is specified.

Developer Email Enforcement

If a user's email matches any email in the developerEmails array, their role is automatically set to Developer on create or update.

Access Control

The plugin modifies the Users collection to add:

  • A multi-select role field with options: Developer, Admin, Editor
  • beforeValidate hooks to enforce first user and developer email rules
  • Access control functions to prevent privilege escalation

Development

This plugin is part of a monorepo. To develop locally:

# Install dependencies
pnpm install

# Start dev server
pnpm dev

License

MIT