1
1
import type { AcceptedLanguages } from '@payloadcms/translations'
2
2
import type { CollectionConfig , Config } from 'payload'
3
3
4
+ import chalk from 'chalk'
5
+
4
6
import type { PluginDefaultTranslationsObject } from './translations/types.js'
5
7
import type { MultiTenantPluginConfig } from './types.js'
6
8
@@ -141,6 +143,9 @@ export const multiTenantPlugin =
141
143
[ [ ] , [ ] ] ,
142
144
)
143
145
146
+ // used to validate enabled collection slugs
147
+ const multiTenantCollectionsFound : string [ ] = [ ]
148
+
144
149
/**
145
150
* The folders collection is added AFTER the plugin is initialized
146
151
* so if they added the folder slug to the plugin collections,
@@ -151,6 +156,7 @@ export const multiTenantPlugin =
151
156
: 'payload-folders'
152
157
153
158
if ( collectionSlugs . includes ( foldersSlug ) ) {
159
+ multiTenantCollectionsFound . push ( foldersSlug )
154
160
const overrides = pluginConfig . collections [ foldersSlug ] ?. tenantFieldOverrides
155
161
? pluginConfig . collections [ foldersSlug ] ?. tenantFieldOverrides
156
162
: pluginConfig . tenantField || { }
@@ -300,6 +306,7 @@ export const multiTenantPlugin =
300
306
} ) ,
301
307
]
302
308
} else if ( pluginConfig . collections ?. [ collection . slug ] ) {
309
+ multiTenantCollectionsFound . push ( collection . slug )
303
310
const isGlobal = Boolean ( pluginConfig . collections [ collection . slug ] ?. isGlobal )
304
311
305
312
if ( isGlobal ) {
@@ -386,6 +393,22 @@ export const multiTenantPlugin =
386
393
throw new Error ( `Tenants collection not found with slug: ${ tenantsCollectionSlug } ` )
387
394
}
388
395
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
+
389
412
/**
390
413
* Add TenantSelectionProvider to admin providers
391
414
*/
0 commit comments