fix(plugin-multi-tenant): respect undefined initialValue and userHasAccessToAllTenants on single-tenant auto-select (#17833) - #17842
Open
Rodrigoue9 wants to merge 1 commit into
Open
Conversation
…ccessToAllTenants on single-tenant auto-select (payloadcms#17833)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 Summary
Fixes #17833
Fixes an issue in
@payloadcms/plugin-multi-tenantwhere single-tenant auto-selection overrode the server's intentional "no tenant selected" state on every page mount for users withuserHasAccessToAllTenants.🔍 Root Cause Analysis
When an installation had exactly one tenant,
TenantSelectionProviderunconditionally auto-selected the first tenant and wrote thepayload-tenantcookie, ignoring whether the user had global access (userHasAccessToAllTenants) and desired an unselected platform-wide view. On the client, the sync effect andsetTenantalso forced re-selection of the single tenant even when clearing the selection or wheninitialValuewas undefined.🛠️ Solution
TenantSelectionProvider(server component), checkeduserHasAccessToAllTenants(user)before falling back to auto-selecting the single tenant, ensuring users with global access retaininitialValue = undefinedwhen no tenant cookie is set.TenantSelectionProviderClient, only auto-select the single tenant and set the cookie ifinitialValueis defined, and allowsetTenant({ id: undefined })to clear tenant selection regardless of tenant count.packages/plugin-multi-tenant/src/providers/TenantSelectionProvider/tenantSelection.unit.test.ts.