Skip to content

Conversation

NicolasLopes7
Copy link
Contributor

@NicolasLopes7 NicolasLopes7 commented Oct 13, 2025

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.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Bug Fixes

    • Sign-in flow improved: the enterprise account chooser now appears only when multiple enterprise SSO connections are available, removing an unnecessary step for single-connection setups.
  • Chores

    • Added a changeset entry preparing a patch release for Clerk JS.

…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.
Copy link

changeset-bot bot commented Oct 13, 2025

🦋 Changeset detected

Latest commit: 967f722

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch

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

Copy link

vercel bot commented Oct 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Oct 14, 2025 1:16pm

Copy link
Contributor

coderabbitai bot commented Oct 13, 2025

Walkthrough

Updates 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

Cohort / File(s) Summary
Release changeset
./changeset/thick-rice-heal.md
Adds a changeset entry bumping Clerk JS to a patch and documenting the sign-in chooser visibility change.
SignIn enterprise flow logic
packages/clerk-js/src/ui/components/SignIn/shared.ts
Replaces an all()-based check with a filter/count: identifies supported_first_factors that include both enterpriseConnectionId and enterpriseConnectionName and returns true if more than one exists; this controls whether the enterprise account chooser is displayed.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A patch-nosed rabbit hops along,
I count the doors and hum a song—
If two or more invite my nose,
I choose between the comfy rows.
Off I go, through login light,
Whiskers twitching, swift and bright. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly captures the core fix by stating that the enterprise accounts chooser is now displayed only when multiple connections are available, matching the changes made in the pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch nicolas/only-trigger-enteprise-accounts-chooser-when-more-than-one-entc

📜 Recent 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.

📥 Commits

Reviewing files that changed from the base of the PR and between cba4c31 and 967f722.

📒 Files selected for processing (1)
  • .changeset/thick-rice-heal.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
.changeset/**

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/thick-rice-heal.md
🪛 LanguageTool
.changeset/thick-rice-heal.md

[grammar] ~5-~5: There might be a mistake here.
Context: ...erk/clerk-js': patch --- Only navigate to enterprise connections chooser when the...

(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)
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 input factors 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.

📥 Commits

Reviewing files that changed from the base of the PR and between dbff913 and cba4c31.

📒 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
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly 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
Use const assertions for literal types: as const
Use satisfies 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 ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly 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.

Copy link

pkg-pr-new bot commented Oct 13, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6983

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6983

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6983

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6983

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6983

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6983

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6983

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6983

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6983

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6983

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6983

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6983

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6983

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6983

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6983

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6983

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6983

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6983

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6983

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6983

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6983

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6983

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6983

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6983

commit: 967f722

@LauraBeatris LauraBeatris enabled auto-merge (squash) October 14, 2025 13:15
@LauraBeatris LauraBeatris merged commit 4531215 into main Oct 14, 2025
44 of 45 checks passed
@LauraBeatris LauraBeatris deleted the nicolas/only-trigger-enteprise-accounts-chooser-when-more-than-one-entc branch October 14, 2025 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants