This plugin sets up multi-tenancy for your application from within your Admin Panel. It does so by adding a tenant field to all specified collections. Your front-end application can then query data by tenant. You must add the Tenants collection so you control what fields are available for each tenant.
Adds a tenant selector to the admin panel, allowing you to switch between tenants
Filters list view results by selected tenant
Filters relationship fields by selected tenant
Ability to create "global" like collections, 1 doc per tenant
Automatically assign a tenant to new documents
Warning
By default this plugin cleans up documents when a tenant is deleted. You should ensure you have strong access control on your tenants collection to prevent deletions by unauthorized users.
You can disabled this behavior by setting cleanupAfterTenantDelete to false in the plugin options.
The plugin scaffolds out everything you will need to separate data by tenant. You can use the tenant field to filter data from enabled collections in your front-end application.
In your frontend you can query and constrain data by tenant with the following:
1
const pagesBySlug =await payload.find({
2
collection:'pages',
3
depth:1,
4
draft:false,
5
limit:1000,
6
overrideAccess:false,
7
where:{
8
// your constraint would depend on the
9
// fields you added to the tenants collection
10
// here we are assuming a slug field exists
11
// on the tenant collection, like in the example above