-
Notifications
You must be signed in to change notification settings - Fork 397
fix(clerk-js): Only show enterprise accounts chooser with multiple connections #6983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(clerk-js): Only show enterprise accounts chooser with multiple connections #6983
Conversation
…nnections Fix logic to only display enterprise accounts chooser when there are multiple enterprise connections available as supported first factors, instead of showing it for every enterprise SSO sign-in.
🦋 Changeset detectedLatest commit: 967f722 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 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.
|
WalkthroughUpdates a Clerk JS changeset and changes sign-in logic so the enterprise account chooser is shown only when more than one supported enterprise SSO factor has both an enterpriseConnectionId and enterpriseConnectionName. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant UI as SignIn UI
participant Logic as hasMultipleEnterpriseConnections
participant Factors as supported_first_factors
participant Chooser as EnterpriseAccountChooser
User->>UI: Open Sign-In
UI->>Factors: Load supported_first_factors
UI->>Logic: Are there multiple enterprise connections?
Logic->>Factors: Filter factors with enterpriseConnectionId & enterpriseConnectionName
Logic-->>UI: Return true if count > 1
alt >1 enterprise connections
UI->>Chooser: Show enterprise chooser
else <=1 enterprise connection
UI-->>User: Proceed with regular sign-in
end
note over UI,Chooser: Chooser shown only when >1 valid enterprise SSO factors
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1).changeset/**📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Files:
🪛 LanguageTool.changeset/thick-rice-heal.md[grammar] ~5-~5: There might be a mistake here. (QB_NEW_EN) ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
packages/clerk-js/src/ui/components/SignIn/shared.ts (2)
66-72
: Update JSDoc to reflect the actual implementation.The JSDoc comment states the function "checks if all factors in the array are enterprise SSO factors," but the implementation actually checks if there are more than one enterprise SSO factor in the array. The comment is misleading.
Apply this diff to correct the documentation:
/** - * Type guard that checks if all factors in the array are enterprise SSO factors - * with both `enterpriseConnectionId` and `enterpriseConnectionName` properties. + * Checks if there are multiple enterprise SSO factors in the array that have + * both `enterpriseConnectionId` and `enterpriseConnectionName` properties. * This is used to determine if the user should be presented with a choice * between multiple enterprise connections. * @experimental */
73-75
: Type guard is incorrect and misleading.The type guard return type claims that when the function returns
true
, all factors in the inputfactors
array are enterprise SSO factors with the required properties. However, the implementation only filters for enterprise factors and checks if there are more than one—it doesn't guarantee that ALL factors are enterprise factors.This creates a false type narrowing that could lead to runtime errors if consuming code relies on this type guard.
Solution 1 (Recommended): Remove the type guard
If the function is only used as a boolean check, remove the type guard:
function hasMultipleEnterpriseConnections( factors: SignInFirstFactor[] | null, -): factors is Array<EnterpriseSSOFactor & { enterpriseConnectionId: string; enterpriseConnectionName: string }> { +): boolean {Solution 2: Return filtered factors for accurate type narrowing
If you need the filtered factors elsewhere, return them instead:
-function hasMultipleEnterpriseConnections( +function getMultipleEnterpriseConnections( factors: SignInFirstFactor[] | null, -): factors is Array<EnterpriseSSOFactor & { enterpriseConnectionId: string; enterpriseConnectionName: string }> { +): Array<EnterpriseSSOFactor & { enterpriseConnectionId: string; enterpriseConnectionName: string }> | null { if (!factors?.length) { - return false; + return null; } - return ( - factors.filter( + const enterpriseFactors = factors.filter( factor => factor.strategy === 'enterprise_sso' && 'enterpriseConnectionId' in factor && 'enterpriseConnectionName' in factor, - ).length > 1 - ); + ) as Array<EnterpriseSSOFactor & { enterpriseConnectionId: string; enterpriseConnectionName: string }>; + + return enterpriseFactors.length > 1 ? enterpriseFactors : null; }
🧹 Nitpick comments (1)
.changeset/thick-rice-heal.md (1)
5-8
: Clarify “multiple orgs” phrasing in changeset.The runtime change hinges on the number of enterprise connections, not orgs. Consider rewording the summary to avoid confusion for release notes readers.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
.changeset/thick-rice-heal.md
(1 hunks)packages/clerk-js/src/ui/components/SignIn/shared.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
packages/clerk-js/src/ui/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/clerk-js-ui.mdc)
packages/clerk-js/src/ui/**/*.{ts,tsx}
: Element descriptors should always be camelCase
Use element descriptors in UI components to enable consistent theming and styling via appearance.elements
Element descriptors should generate unique, stable CSS classes for theming
Element descriptors should handle state classes (e.g., cl-loading, cl-active, cl-error, cl-open) automatically based on component state
Do not render hard-coded values; all user-facing strings must be localized using provided localization methods
Use the useLocalizations hook and localizationKeys utility for all text and error messages
Use the styled system (sx prop, theme tokens, responsive values) for custom component styling
Use useCardState for card-level state, useFormState for form-level state, and useLoadingStatus for loading states
Always use handleError utility for API errors and use translateError for localized error messages
Use useFormControl for form field state, implement proper validation, and handle loading and error states in forms
Use localization keys for all form labels and placeholders
Use element descriptors for consistent styling and follow the theme token system
Use the Card and FormContainer patterns for consistent UI structure
Files:
packages/clerk-js/src/ui/components/SignIn/shared.ts
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/clerk-js/src/ui/components/SignIn/shared.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/clerk-js/src/ui/components/SignIn/shared.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/src/ui/components/SignIn/shared.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/clerk-js/src/ui/components/SignIn/shared.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/clerk-js/src/ui/components/SignIn/shared.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/clerk-js/src/ui/components/SignIn/shared.ts
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/thick-rice-heal.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Build Packages
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
packages/clerk-js/src/ui/components/SignIn/shared.ts (1)
80-87
: Implementation logic correctly checks for multiple enterprise connections.The filtering and counting logic properly identifies when there are multiple enterprise SSO factors with the required properties, which aligns with the PR objective of only showing the enterprise accounts chooser when multiple connections are available.
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
Description
Fix logic to only display enterprise accounts chooser when there are multiple enterprise connections available as supported first factors, instead of showing it for every enterprise SSO sign-in.
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit
Bug Fixes
Chores