payloadcms

multi tenant

Official
by payloadcms
payload
Roles & permissions
v3
v4
4.0.0-canary.20261205 · prerelease
MIT

Overview

Summary generated from the README

Adds multi-tenancy to Payload by injecting a tenant field into selected collections and a tenants array field into the users collection. It applies tenant-based access constraints and list filters, and adds a tenant selector to the admin panel. Tenants live in a configurable collection, and super-admin access can be defined with a custom function.

Features

  • Adds a tenant relationship field to each collection you enable
  • Merges tenant constraints into collection access control, with opt-out per collection
  • Treats collections as per-tenant globals using the isGlobal option
  • Adds a tenants array field to users, exportable for custom placement
  • Cleans up related documents and user references after a tenant is deleted
  • Tenant selector in the admin with customizable, localizable label

Use cases

  • Run several client sites from one Payload instance with separated content
  • Give each tenant's editors access only to their own documents
  • Keep per-tenant navigation or settings using collections that behave as globals

From the author

Multi Tenant plugin for Payload

Installation

npm i @payloadcms/plugin-multi-tenant

46.1k

Stars

4.5k

Forks

1821

Open Issues

Today

Last Updated

165.4k

Weekly Downloads

v3.94.2

npm Version

441.8 KB

Unpacked Size

0

Dependencies

Repository stars

46.1K+1.8K since Sep 6

Show data
Repository stars by day (UTC)
DateStars
Dec 5, 202646,136
Dec 4, 202646,125
Dec 3, 202646,106
Dec 2, 202646,087
Dec 1, 202646,068
Nov 30, 202646,059
Nov 29, 202646,037
Nov 28, 202646,035
Nov 27, 202646,022
Nov 26, 202646,012
Nov 25, 202645,993
Nov 24, 202645,976
Nov 23, 202645,958
Nov 22, 202645,947
Nov 21, 202645,937
Nov 20, 202645,926
Nov 19, 202645,901
Nov 18, 202645,868
Nov 17, 202645,852
Nov 16, 202645,831
Nov 15, 202645,820
Nov 14, 202645,807
Nov 13, 202645,792
Nov 12, 202645,779
Nov 11, 202645,763
Nov 10, 202645,742
Nov 9, 202645,731
Nov 8, 202645,722
Nov 7, 202645,704
Nov 6, 202645,681
Nov 5, 202645,670
Nov 4, 202645,647
Nov 3, 202645,629
Nov 2, 202645,611
Nov 1, 202645,603
Oct 31, 202645,592
Oct 30, 202645,574
Oct 29, 202645,561
Oct 28, 202645,543
Oct 27, 202645,519
Oct 26, 202645,492
Oct 25, 202645,472
Oct 24, 202645,449
Oct 23, 202645,430
Oct 22, 202645,405
Oct 21, 202645,259
Oct 20, 202645,239
Oct 19, 202645,213
Oct 18, 202645,192
Oct 17, 202645,165
Oct 16, 202645,148
Oct 15, 202645,122
Oct 14, 202645,100
Oct 13, 202645,082
Oct 12, 202645,057
Oct 11, 202645,032
Oct 10, 202645,023
Oct 9, 202645,003
Oct 8, 202644,983
Oct 7, 202644,959
Oct 6, 202644,935
Oct 5, 202644,924
Oct 4, 202644,907
Oct 3, 202644,891
Oct 2, 202644,876
Oct 1, 202644,859
Sep 30, 202644,846
Sep 29, 202644,829
Sep 28, 202644,805
Sep 27, 202644,787
Sep 26, 202644,769
Sep 25, 202644,737
Sep 24, 202644,709
Sep 23, 202644,691
Sep 22, 202644,669
Sep 21, 202644,641
Sep 20, 202644,628
Sep 19, 202644,609
Sep 18, 202644,595
Sep 17, 202644,570
Sep 16, 202644,548
Sep 15, 202644,523
Sep 14, 202644,501
Sep 13, 202644,488
Sep 12, 202644,470
Sep 11, 202644,447
Sep 10, 202644,427
Sep 9, 202644,402
Sep 8, 202644,384
Sep 7, 202644,364
Sep 6, 202644,352

Shared by 12 plugins in payloadcms/payload.

npm weekly downloads

159.6K+86.6K since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 2026159,635
Dec 4, 2026154,627
Dec 3, 2026145,959
Dec 2, 2026149,385
Dec 1, 2026153,268
Nov 30, 2026153,198
Nov 29, 2026151,139
Nov 28, 2026157,961
Nov 27, 2026161,426
Nov 26, 2026167,509
Nov 25, 2026165,771
Nov 24, 2026164,790
Nov 23, 2026165,356
Nov 22, 2026165,510
Nov 21, 2026167,204
Nov 20, 2026165,850
Nov 19, 2026161,128
Nov 18, 2026154,261
Nov 17, 2026151,390
Nov 16, 2026151,679
Nov 15, 2026154,638
Nov 14, 2026147,972
Nov 13, 2026153,025
Nov 12, 2026154,576
Nov 11, 2026159,944
Nov 10, 2026166,382
Nov 9, 2026169,354
Nov 8, 2026167,478
Nov 7, 2026169,634
Nov 6, 2026166,556
Nov 5, 2026164,187
Nov 4, 2026160,739
Nov 3, 2026156,792
Nov 2, 2026155,302
Nov 1, 2026156,227
Oct 31, 2026155,939
Oct 30, 2026151,358
Oct 29, 2026125,733
Oct 28, 2026100,085
Oct 27, 2026100,055
Oct 26, 2026110,158
Oct 25, 2026118,154
Oct 24, 2026113,158
Oct 23, 202690,308
Oct 22, 2026116,888
Oct 21, 2026137,458
Oct 20, 2026134,040
Oct 19, 2026121,128
Oct 18, 2026107,865
Oct 17, 2026110,666
Oct 16, 2026137,160
Oct 15, 2026131,897
Oct 14, 2026133,072
Oct 13, 2026131,964
Oct 12, 2026132,211
Oct 11, 2026128,712
Oct 10, 2026129,787
Oct 9, 2026124,155
Oct 8, 2026124,592
Oct 7, 2026122,780
Oct 6, 2026123,345
Oct 5, 2026122,758
Oct 4, 2026126,069
Oct 3, 2026119,414
Oct 2, 2026119,503
Oct 1, 2026116,728
Sep 30, 2026116,009
Sep 29, 2026112,246
Sep 28, 2026108,674
Sep 27, 2026100,424
Sep 26, 202696,694
Sep 25, 202691,621
Sep 24, 202688,613
Sep 23, 202685,408
Sep 22, 202686,416
Sep 21, 202687,716
Sep 20, 202695,114
Sep 19, 202696,399
Sep 18, 202694,393
Sep 17, 202690,340
Sep 16, 202685,505
Sep 15, 202686,621
Sep 14, 202684,947
Sep 13, 202676,976
Sep 12, 202675,997
Sep 11, 202675,431
Sep 10, 202675,280
Sep 9, 202675,172
Sep 8, 202672,948
Sep 7, 202672,490
Sep 6, 202673,062

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

Health Score

100/100Excellent

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/official-plugin-multi-tenant.svg)](https://payloaddirectory.dev/plugins/official-plugin-multi-tenant)
HTML
<a href="https://payloaddirectory.dev/plugins/official-plugin-multi-tenant"><img src="https://payloaddirectory.dev/badge/official-plugin-multi-tenant.svg" alt="Payload Directory"></a>
Updated Dec 5, 2026Created Jan 5, 2021Published Nov 24, 2026

README

Multi Tenant Plugin

A plugin for Payload to easily manage multiple tenants from within your admin panel.

Installation

pnpm add @payloadcms/plugin-multi-tenant

Plugin Types

type MultiTenantPluginConfig<ConfigTypes = unknown> = {
  /**
   * After a tenant is deleted, the plugin will attempt to clean up related documents
   * - removing documents with the tenant ID
   * - removing the tenant from users
   *
   * @default true
   */
  cleanupAfterTenantDelete?: boolean
  /**
   * Automatically
   */
  collections: {
    [key in CollectionSlug]?: {
      /**
       * Set to `true` if you want the collection to behave as a global
       *
       * @default false
       */
      isGlobal?: boolean
      /**
       * Set to `false` if you want to manually apply the baseFilter
       *
       * @default true
       */
      useBaseFilter?: boolean
      /**
       * Set to `false` if you want to handle collection access manually without the multi-tenant constraints applied
       *
       * @default true
       */
      useTenantAccess?: boolean
    }
  }
  /**
   * Enables debug mode
   * - Makes the tenant field visible in the admin UI within applicable collections
   *
   * @default false
   */
  debug?: boolean
  /**
   * Enables the multi-tenant plugin
   *
   * @default true
   */
  enabled?: boolean
  /**
   * Field configuration for the field added to all tenant enabled collections
   */
  tenantField?: {
    access?: RelationshipField['access']
    /**
     * The name of the field added to all tenant enabled collections
     *
     * @default 'tenant'
     */
    name?: string
  }
  /**
   * Field configuration for the field added to the users collection
   *
   * If `includeDefaultField` is `false`, you must include the field on your users collection manually
   * This is useful if you want to customize the field or place the field in a specific location
   */
  tenantsArrayField?:
    | {
        /**
         * Access configuration for the array field
         */
        arrayFieldAccess?: ArrayField['access']
        /**
         * Name of the array field
         *
         * @default 'tenants'
         */
        arrayFieldName?: string
        /**
         * Name of the tenant field
         *
         * @default 'tenant'
         */
        arrayTenantFieldName?: string
        /**
         * When `includeDefaultField` is `true`, the field will be added to the users collection automatically
         */
        includeDefaultField?: true
        /**
         * Additional fields to include on the tenants array field
         */
        rowFields?: Field[]
        /**
         * Access configuration for the tenant field
         */
        tenantFieldAccess?: RelationshipField['access']
      }
    | {
        arrayFieldAccess?: never
        arrayFieldName?: string
        arrayTenantFieldName?: string
        /**
         * When `includeDefaultField` is `false`, you must include the field on your users collection manually
         */
        includeDefaultField?: false
        rowFields?: never
        tenantFieldAccess?: never
      }
  /**
   * Customize tenant selector label
   *
   * Either a string or an object where the keys are i18n codes and the values are the string labels
   */
  tenantSelectorLabel?:
    | Partial<{
        [key in AcceptedLanguages]?: string
      }>
    | string
  /**
   * The slug for the tenant collection
   *
   * @default 'tenants'
   */
  tenantsSlug?: string
  /**
   * Function that determines if a user has access to _all_ tenants
   *
   * Useful for super-admin type users
   */
  userHasAccessToAllTenants?: (
    user: ConfigTypes extends { user: unknown } ? ConfigTypes['user'] : User,
  ) => boolean
  /**
   * Opt out of adding access constraints to the tenants collection
   */
  useTenantsCollectionAccess?: boolean
  /**
   * Opt out including the baseListFilter to filter tenants by selected tenant
   */
  useTenantsListFilter?: boolean
  /**
   * Opt out including the baseListFilter to filter users by selected tenant
   */
  useUsersTenantFilter?: boolean
}

How to configure Collections as Globals for multi-tenant

When using multi-tenant, globals need to actually be configured as collections so the content can be specific per tenant. To do that, you can mark a collection with isGlobal and it will behave like a global and users will not see the list view.

multiTenantPlugin({
  collections: {
    navigation: {
      isGlobal: true,
    },
  },
})

Customizing access control

In some cases, the access control supplied out of the box may be too strict. For example, if you need some documents to be shared between tenants, you will need to opt out of the supplied access control functionality.

By default this plugin merges your access control result with a constraint based on tenants the user has access to within an AND condition. That would not work for the above scenario.

In the multi-tenant plugin config you can set useTenantAccess to false:

// File: payload.config.ts

import { buildConfig } from 'payload'
import { multiTenantPlugin } from '@payloadcms/plugin-multi-tenant'
import { getTenantAccess } from '@payloadcms/plugin-multi-tenant/utilities'
import { Config as ConfigTypes } from './payload-types'

// Add the plugin to your payload config
export default buildConfig({
  plugins: [
    multiTenantPlugin<ConfigTypes>({
      collections: {
        media: {
          useTenantAccess: false,
        },
      },
    }),
  ],
  collections: [
    {
      slug: 'media',
      fields: [
        {
          name: 'isShared',
          type: 'checkbox',
          defaultValue: false,
          // you likely want to set access control on fields like this
          // to prevent just any user from modifying it
        },
      ],
      access: {
        read: ({ req, doc }) => {
          if (!req.user) return false

          const whereConstraint = {
            or: [
              {
                isShared: {
                  equals: true,
                },
              },
            ],
          }

          const tenantAccessResult = getTenantAccess({ user: req.user })

          if (tenantAccessResult) {
            whereConstraint.or.push(tenantAccessResult)
          }

          return whereConstraint
        },
      },
    },
  ],
})

Placing the tenants array field

In your users collection you may want to place the field in a tab or in the sidebar, or customize some of the properties on it.

You can use the tenantsArrayField.includeDefaultField: false setting in the plugin config. You will then need to manually add a tenants array field in your users collection.

This field cannot be nested inside a named field, ie a group, named-tab or array. It can be nested inside a row, unnamed-tab, collapsible.

To make it easier, this plugin exports the field for you to import and merge in your own properties.

import type { CollectionConfig } from 'payload'
import { tenantsArrayField } from '@payloadcms/plugin-multi-tenant/fields'

const customTenantsArrayField = tenantsArrayField({
  arrayFieldAccess: {}, // access control for the array field
  tenantFieldAccess: {}, // access control for the tenants field on the array row
  rowFields: [], // additional row fields
})

export const UsersCollection: CollectionConfig = {
  slug: 'users',
  fields: [
    {
      ...customTenantsArrayField,
      label: 'Associated Tenants',
    },
  ],
}

Similar plugins

View on GitHubView on npmOfficial Payload plugin