Skip to content

Commit 8157f4c

Browse files
authored
fix(plugin-multi-tenant): modal container blocks clicks on create-first-user page (#15973)
# Overview Fixes the `@faceless-ui/modal` container blocking clicks on the `/admin/create-first-user` page when the multi-tenant plugin is active. Also guards against the admin users collection being listed in `pluginConfig.collections`. ## Key Changes - Gate `openModal` behind `showField` and early-return in `debug`/`isEditManyModalOpen` modes — modal only opens when there are tenant options to display - Skip Pass 2 for the admin users collection if listed in `pluginConfig.collections`, with a `console.warn` — prevents double access control, conflicting tenant fields, and validation errors on user creation - Exclude admin users slug from `collectionSlugs` upfront to suppress the spurious missing-collections warning ## Design Decisions `(!value && !selectedTenantID)` had no `showField` guard, so `openModal` fired even with zero tenants. On `create-first-user` this left the modal container active with `pointer-events: all` and no content, blocking form clicks. `users: {}` in `pluginConfig.collections` is always a misconfiguration — Pass 1 already handles users via `tenantsArrayField`. Pass 2 processing them again adds a conflicting `tenantField` and breaks user creation. Warn-and-skip was chosen over a hard throw to stay non-breaking. Fixes #15288
1 parent f89e736 commit 8157f4c

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

packages/plugin-multi-tenant/src/components/TenantField/index.client.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,24 @@ export const TenantField = ({ debug, unique, ...fieldArgs }: Props) => {
109109
}, [unique, options, selectedTenantID, setTenant, value, setEntityType, entityType])
110110

111111
React.useEffect(() => {
112-
if (unique) {
112+
if (unique || debug || isEditManyModalOpen) {
113113
return
114114
}
115-
if ((!isFormValid && showError && showField) || (!value && !selectedTenantID)) {
115+
if (showField && ((!isFormValid && showError) || (!value && !selectedTenantID))) {
116116
openModal(assignTenantModalSlug)
117117
}
118-
}, [isFormValid, showError, showField, openModal, value, docID, selectedTenantID, unique])
118+
}, [
119+
debug,
120+
isEditManyModalOpen,
121+
isFormValid,
122+
showError,
123+
showField,
124+
openModal,
125+
value,
126+
docID,
127+
selectedTenantID,
128+
unique,
129+
])
119130

120131
if (showField) {
121132
if (debug || isEditManyModalOpen) {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ export const multiTenantPlugin =
135135
[string[], string[]]
136136
>(
137137
(acc, slug) => {
138+
if (slug === adminUsersCollection.slug) {
139+
return acc
140+
}
138141
if (pluginConfig?.collections?.[slug]?.isGlobal) {
139142
acc[1].push(slug)
140143
} else {
@@ -336,6 +339,13 @@ export const multiTenantPlugin =
336339
}),
337340
]
338341
} else if (pluginConfig.collections?.[collection.slug]) {
342+
if (collection.slug === adminUsersCollection.slug) {
343+
// eslint-disable-next-line no-console
344+
console.warn(
345+
`[plugin-multi-tenant] The admin users collection "${collection.slug}" should not be listed in pluginConfig.collections — it is already handled by the plugin. Skipping tenant-field processing for this collection to avoid double access control and validation errors.`,
346+
)
347+
return
348+
}
339349
multiTenantCollectionsFound.push(collection.slug)
340350
const isGlobal = Boolean(pluginConfig.collections[collection.slug]?.isGlobal)
341351

0 commit comments

Comments
 (0)