Skip to content

Commit 76741eb

Browse files
chore(plugin-multi-tenant): missing collections warning (#13538)
Fixes #13517 ⚠️ **Need to merge #13379 first** Adds warning if collections are enabled but not found. This can happen if you add the multi-tenant before other plugins that add the collections you are attempting to add multi-tenancy to.
1 parent 2bdd669 commit 76741eb

File tree

1 file changed

+23
-0
lines changed
  • packages/plugin-multi-tenant/src

1 file changed

+23
-0
lines changed

packages/plugin-multi-tenant/src/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { AcceptedLanguages } from '@payloadcms/translations'
22
import type { CollectionConfig, Config } from 'payload'
33

4+
import chalk from 'chalk'
5+
46
import type { PluginDefaultTranslationsObject } from './translations/types.js'
57
import type { MultiTenantPluginConfig } from './types.js'
68

@@ -141,6 +143,9 @@ export const multiTenantPlugin =
141143
[[], []],
142144
)
143145

146+
// used to validate enabled collection slugs
147+
const multiTenantCollectionsFound: string[] = []
148+
144149
/**
145150
* The folders collection is added AFTER the plugin is initialized
146151
* so if they added the folder slug to the plugin collections,
@@ -151,6 +156,7 @@ export const multiTenantPlugin =
151156
: 'payload-folders'
152157

153158
if (collectionSlugs.includes(foldersSlug)) {
159+
multiTenantCollectionsFound.push(foldersSlug)
154160
const overrides = pluginConfig.collections[foldersSlug]?.tenantFieldOverrides
155161
? pluginConfig.collections[foldersSlug]?.tenantFieldOverrides
156162
: pluginConfig.tenantField || {}
@@ -300,6 +306,7 @@ export const multiTenantPlugin =
300306
}),
301307
]
302308
} else if (pluginConfig.collections?.[collection.slug]) {
309+
multiTenantCollectionsFound.push(collection.slug)
303310
const isGlobal = Boolean(pluginConfig.collections[collection.slug]?.isGlobal)
304311

305312
if (isGlobal) {
@@ -386,6 +393,22 @@ export const multiTenantPlugin =
386393
throw new Error(`Tenants collection not found with slug: ${tenantsCollectionSlug}`)
387394
}
388395

396+
if (
397+
multiTenantCollectionsFound.length !==
398+
collectionSlugs.length + globalCollectionSlugs.length
399+
) {
400+
const missingSlugs = [...collectionSlugs, ...globalCollectionSlugs].filter(
401+
(slug) => !multiTenantCollectionsFound.includes(slug),
402+
)
403+
// eslint-disable-next-line no-console
404+
console.error(
405+
chalk.yellow.bold('WARNING (plugin-multi-tenant)'),
406+
'missing collections',
407+
missingSlugs,
408+
'try placing the multi-tenant plugin after other plugins.',
409+
)
410+
}
411+
389412
/**
390413
* Add TenantSelectionProvider to admin providers
391414
*/

0 commit comments

Comments
 (0)