feat(clerk-js,ui): Auto-activate exclusive organization in choose-organization task#8933
Conversation
…anization task Parse the `exclusive_membership` field on the Organization resource and expose it as `Organization.exclusiveMembership`. When the `choose-organization` session task fires for a member of an organization that enforces exclusive membership, skip the org picker and auto-call setActive on that organization behind the existing loading spinner. If activation fails, surface the error via card state and fall back to the regular flows so the user can recover. The generic, instance-wide force-choose-organization path is unchanged when the field is absent or false.
🦋 Changeset detectedLatest commit: 232e4fe The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdds ChangesExclusive Membership Auto-Activation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/eslint-plugin
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
The optional `exclusiveMembership?: boolean` broke the `@clerk/shared` typecheck: `PrimitiveKeys<OrganizationResource>` is a homomorphic mapped type, so an optional property preserves its `?` modifier and injects `undefined` into the indexed-access union, violating the `LooseExtractedParams<T extends string>` constraint in clerk.ts. Mirror `selfServeSSOEnabled` (also an instance-gated `*bool,omitempty` on the backend): required `boolean`, defaulted to `false` when the FAPI field is absent. Detection (`organization.exclusiveMembership === true`) is unchanged.
API Changes Report
Summary
@clerk/nuxtCurrent version: 2.6.5 Subpath
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/shared/src/types/organization.ts (1)
100-103: Flag this public JSDoc change for Docs-team review.This updates customer-facing JSDoc for
OrganizationResource.exclusiveMembership; please confirm the generated reference docs output is reviewed for wording/behavior alignment.As per coding guidelines,
packages/**treats JSDoc on public/reference-facing APIs as customer-facing docs and asks for Docs-team review when those docs change.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/shared/src/types/organization.ts` around lines 100 - 103, The JSDoc for the public API property exclusiveMembership in the OrganizationResource type has been updated, which constitutes a customer-facing documentation change per coding guidelines for packages/**. Flag this change for the Docs-team to review and ensure they validate that the generated reference documentation accurately reflects the updated JSDoc wording and correctly describes the behavior of the exclusiveMembership flag regarding exclusive organizational membership enforcement.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsx`:
- Around line 77-80: In the catch block that handles the auto-activation error,
reorder the statements so that setAutoActivateFailed(true) is called before
handleError(err, [], card.setError). Since handleError rethrows unknown errors,
placing setAutoActivateFailed after it may prevent the fallback picker state
from being set. Move setAutoActivateFailed(true) to execute first in the catch
block to ensure the fallback behavior is triggered regardless of whether
handleError rethrows.
---
Nitpick comments:
In `@packages/shared/src/types/organization.ts`:
- Around line 100-103: The JSDoc for the public API property exclusiveMembership
in the OrganizationResource type has been updated, which constitutes a
customer-facing documentation change per coding guidelines for packages/**. Flag
this change for the Docs-team to review and ensure they validate that the
generated reference documentation accurately reflects the updated JSDoc wording
and correctly describes the behavior of the exclusiveMembership flag regarding
exclusive organizational membership enforcement.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Repository UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 1c6f9abf-7b63-4337-a547-6857f63da5f1
📒 Files selected for processing (5)
.changeset/exclusive-membership-auto-activate.mdpackages/clerk-js/src/core/resources/Organization.tspackages/shared/src/types/json.tspackages/shared/src/types/organization.tspackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsx
| } catch (err: any) { | ||
| handleError(err, [], card.setError); | ||
| setAutoActivateFailed(true); | ||
| } |
There was a problem hiding this comment.
Set fallback state before delegating to handleError in the auto-activation catch path.
handleError rethrows unknown errors, so in the current order setAutoActivateFailed(true) may never run. That breaks the intended “fallback to picker on activation failure” behavior.
💡 Proposed fix
- } catch (err: any) {
- handleError(err, [], card.setError);
- setAutoActivateFailed(true);
+ } catch (err: unknown) {
+ setAutoActivateFailed(true);
+ try {
+ handleError(err, [], card.setError);
+ } catch {
+ card.setError('Something went wrong while activating your organization. Please choose one manually.');
+ }
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsx`
around lines 77 - 80, In the catch block that handles the auto-activation error,
reorder the statements so that setAutoActivateFailed(true) is called before
handleError(err, [], card.setError). Since handleError rethrows unknown errors,
placing setAutoActivateFailed after it may prevent the fallback picker state
from being set. Move setAutoActivateFailed(true) to execute first in the catch
block to ensure the fallback behavior is triggered regardless of whether
handleError rethrows.
What
When the
choose-organizationsession task fires for a member of an exclusive-membership organization, clerk-js now skips the org picker entirely: it shows the loading spinner and auto-callssetActiveon that org. The generic instance-wide force-choose-org flow is unchanged for everyone else.Implements the clerk-js half of exclusive membership "after-auth".
Changes
Organization.exclusiveMembership— parse the FAPIexclusive_membershipfield (@clerk/sharedtypes +clerk-jsOrganization resourcefromJSON/__internal_toSnapshot). Field isundefinedfor non-adopting instances.TaskChooseOrganization— detect the membership whoseorganization.exclusiveMembership === true(an exclusive member belongs to exactly one org). If found: render only the spinner and auto-setActiveonce (useRefsingle-fire guard), reusing the existingnavigateOnSetActive/redirectUrlCompletewiring. On failure, surface the error via card state and fall back to the normal flows so the user can recover. No exclusive membership → existing behavior, zero change.Summary by CodeRabbit
Release Notes
New Features