joas8211

payload tenancy

by joas8211
Roles & permissions
v2
^2.11.1
MIT

Overview

Summary generated from the README

Lets multiple tenants share a single Payload instance while keeping their documents, users and globals separate. It is added through the plugins array and extends your tenant, user and resource collections with tenant fields. It targets Payload 2 and is deprecated by its author, who points to the official multi-tenant plugin for Payload 3.

Features

  • Tenant isolation for resource collections via a hidden tenant field
  • Hierarchical tenants where parents can access their children
  • Three isolation strategies: user, path and domain
  • Per-tenant globals through proxied global collections, with a shared globals opt-out
  • Configurable tenant collection slug and tenant slug and domain fields

Use cases

  • Host several client sites or organizations on one Payload instance with separate content
  • Give each tenant its own domain or URL path with a separate admin login
  • Let parent organizations manage users and content of their sub-tenants

From the author

Multi-tenancy plugin for Payload CMS

Installation

npm i payload-tenancy

179

Stars

11

Forks

0

Open Issues

1 years ago

Last Updated

81

Weekly Downloads

v2.1.2

npm Version

139.6 KB

Unpacked Size

0

Dependencies

GitHub stars

1790 since Sep 7

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

81+71 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 202681
Dec 5, 202637
Dec 4, 202629
Dec 3, 202629
Dec 2, 202631
Dec 1, 202634
Nov 30, 202630
Nov 29, 202637
Nov 28, 202637
Nov 27, 202637
Nov 26, 202632
Nov 25, 202638
Nov 24, 202638
Nov 23, 202638
Nov 22, 202621
Nov 21, 202620
Nov 20, 202635
Nov 19, 202636
Nov 18, 202644
Nov 17, 202642
Nov 16, 202643
Nov 15, 202658
Nov 14, 202656
Nov 13, 202644
Nov 12, 202662
Nov 11, 202647
Nov 10, 202654
Nov 9, 202656
Nov 8, 202640
Nov 7, 202642
Nov 6, 202643
Nov 5, 202632
Nov 4, 202629
Nov 3, 202621
Nov 2, 202620
Nov 1, 202620
Oct 31, 202620
Oct 30, 202620
Oct 29, 202612
Oct 28, 202612
Oct 27, 202614
Oct 26, 202612
Oct 25, 202613
Oct 24, 202613
Oct 23, 20267
Oct 22, 20267
Oct 21, 202612
Oct 20, 202612
Oct 19, 202613
Oct 18, 202612
Oct 17, 202613
Oct 16, 202617
Oct 15, 202618
Oct 14, 202646
Oct 13, 202645
Oct 12, 202646
Oct 11, 202646
Oct 10, 202642
Oct 9, 202641
Oct 8, 202644
Oct 7, 202612
Oct 6, 202611
Oct 5, 20269
Oct 4, 202612
Oct 3, 202618
Oct 2, 202617
Oct 1, 202615
Sep 30, 202615
Sep 29, 202632
Sep 28, 202633
Sep 27, 202630
Sep 26, 202627
Sep 25, 202632
Sep 24, 202635
Sep 23, 202635
Sep 22, 202636
Sep 21, 202635
Sep 20, 202635
Sep 19, 202633
Sep 18, 202629
Sep 17, 202632
Sep 16, 202634
Sep 15, 202617
Sep 14, 202619
Sep 13, 202618
Sep 12, 202618
Sep 11, 202617
Sep 10, 202610
Sep 9, 20268
Sep 8, 202610
Sep 7, 202610

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

Health Score

49/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/600855844-root.svg)](https://payloaddirectory.dev/plugins/600855844-root)
HTML
<a href="https://payloaddirectory.dev/plugins/600855844-root"><img src="https://payloaddirectory.dev/badge/600855844-root.svg" alt="Payload Directory"></a>
Updated Sep 8, 2025Created Feb 12, 2023Published May 26, 2024

README

Multi-tenancy plugin for Payload CMS

This plugin allows multiple tenants to access different resources in the same instance of Payload CMS.

Tenants are an account to the single instance of application (server and database) that make it seem like there's one application instances for each tenant. Each tenant can have multiple users. In this case tenants are also hierarchical, so tenants can also include other tenants.

DEPRECATION NOTICE

Payload Tenancy will not be maintained anymore by Jesse Sivonen (@joas8211) and the repository will be made read-only. This plugin targets Payload 2 which also doesn't seem to receive updates anymore. There seems to be now an official multi-tenant plugin for Payload 3, which I will suggest you to check out instead.

Table of contents

Features

  • Tenant isolation: Each tenant has it's own documents and only that tenant can access them.
  • Hierarchial tenant management: Tenants have parents. Parent tenants can manage and access their children in a hierarchical manner.
  • Path mapping: Each tenant can be mapped to its own path to separate login pages and to allow access to different tenants.
  • Domain mapping: Each tenant can be mapped to its own domain to create clear separation between tenants.
  • Tested properly: The project is tested thoroughly with unit tests, e2e tests and manual testing.

Collections and fields

Here's description of collections used and fields that are added by this plugin.

  • Tenant collection holds information about tenants. The collection is not added automatically, but some fields are added to it. Tenants can be managed in a hierarchial manner. You can access the tenant you belong to and it's sub-tenants.

    The name of the collection must be either "tenants" or defined in plugin's factory function. In example below, tenant collection is named "organizations".

    export default buildConfig({
      plugins: [tenancy({ tenantCollection: "organizations" })],
      collections: [Users, Organizations],
      // ...rest of the config...
    });
    
    • Tenant's slug field contains URL friendly name of the tenant. Slug is required and is used for identifying the tenant from URL path if path isolation is in use.

    • Tenant's domains are optional and are used for identifying the tenant by hostname in domain isolation mode.

  • User collections have a tenant field that connects users to some tenant. The tenant field is required to have relation to some existing tenant. Users can be accessed in a hierarchial manner, so that all above tenants see users in that tenant and below.

  • Other collections are called resource collections because they are resources of one tenant. They also have a hidden tenant field that must relate to an existing tenant. Documents of resource collections can by default be only accessed from the tenant owning those documents determined by path or domain or an user belonging to the tenant when using "user" isolation strategy. Users above in tenant hierarchy can login to tenants below and access resource collections that way.

Globals

Globals are isolated between tenants after version 1.2 by default. The isolation is achieved by creating collection for each global and proxying the global to the correct document of that collection. Global collections are named by global they hold (globalSlug + "Globals", eg. "settingsGlobals") and can only be accessed through the global, or using Local API with overridden access.

To operate on isolated globals using Local API, you must pass user object with a tenant so that the correct document is accessed.

const globalDocument = await payload.findGlobal({
  slug: "settings",
  user: { tenant: someTenantOrId },
});

To opt-out global from tenant isolation you can add the slugs of the globals to sharedGlobals option.

export default buildConfig({
  plugins: [tenancy({ sharedGlobals: ["settings"] })],
  // ...rest of the config...
});

Tenant isolation strategies

There is a few different strategies to choose from to isolate tenants from each other.

  • "user" strategy: All users log in to the same address (URL) and can access their own tenant after logging in. There's no way to isolate publicly available content between tenants.

  • "path" strategy: All tenants have different base path for their "section" of the installation. Admin panel, Rest API, and GraphQL API are all under that base path and access different content. The path to admin panel would be for example "/my-company/admin".

  • "domain" strategy: All tenants have their own domains. And appear as completely different installations for users although they are controlled by single server (or load-balanced cluster). For this to work tenant must have at least one domain set and the name service must point to correct location where you are hosting the application.

You can set the strategy to plugin's factory function. In example below, "domain" strategy is used.

export default buildConfig({
  plugins: [tenancy({ isolationStrategy: "domain" })],
  collections: [Users, Tenants],
  // ...rest of the config...
});

Installation

  1. Install plugin from NPM registry to your Payload project by using you preferred NodeJS package manager. Some example commands below.

    Using npm:

    $ npm install payload-tenancy
    

    Using Yarn:

    $ yarn add payload-tenancy
    
  2. Ensure you have at least one authentication-enabled (user) collection.

  3. Create tenant collection. Use slug "tenants" or configure other slug in the following step.

    export const Tenants: CollectionConfig = {
      slug: "tenants",
      admin: {
        useAsTitle: "name",
      },
      fields: [
        {
          type: "text",
          name: "name",
          label: "Name",
          required: true,
        },
      ],
    };
    
  4. Import and add the plugin to your Payload config.

    export default buildConfig({
      plugins: [tenancy()],
      collections: [Users, Tenants],
      // ...rest of the config...
    });
    

Initial setup

Initial setup can be done in at least two different ways that are described below. To complete initial setup there must be at least one tenant and one user.

Programmatic setup

Setup can be done programmatically using Local API. Just make sure there's at least one tenant and one user that are related to each other by tenant field in user document.

const myTenant = await payload.create({
  collection: "tenants",
  data: {
    slug: "my-company",
    domains: [{ domain: "my-company.local" }],
  },
});

await payload.create({
  collection: "users",
  data: {
    email: "[email protected]",
    password: "secret",
    tenant: myTenant.id,
  },
});

Manual setup

Setup can be done through admin panel using "user" isolation strategy which is the default strategy. First, when you arrive to admin panel when there's no users registered yet, you are greeted with normal Payload's "create first user" form.

Screenshot of create first user form

After creating the first user the dashboard shows only the tenant collection. That's because the root tenant must be created at this stage.

Screenshot of dashboard after registration

Tenant form has fields for slug and domains. Slug is required and is used for identifying the tenant from URL path if path isolation is in use. Domains are optional and are used for identifying the tenant by hostname in domain isolation mode.

Screenshot of tenant form

After creating the root tenant, other collections show and you are free to create other users, tenants or resources owned by the tenant. Setup has been completed.

Similar plugins