javascript icon indicating copy to clipboard operation
javascript copied to clipboard

fix(clerk-js): Fix silent failure with setActive org slug

Open jescalan opened this issue 3 months ago • 6 comments

This pull request contains changes generated by a Cursor Cloud Agent

Open in Cursor Open in Web

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation when selecting an active organization: providing an invalid organization slug now returns a clear, specific error indicating the organization wasn't found or the user isn't a member, preventing silent failures and improving feedback during organization switches.

jescalan avatar Nov 03 '25 15:11 jescalan

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch. Learn more about Cursor Agents

cursor[bot] avatar Nov 03 '25 15:11 cursor[bot]

⚠️ No Changeset found

Latest commit: 022593ddbf8f25770310254ab98549d9af0b1f7e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Nov 03 '25 15:11 changeset-bot[bot]

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 Nov 3, 2025 4:24pm

vercel[bot] avatar Nov 03 '25 15:11 vercel[bot]

Walkthrough

Adds explicit validation in Clerk.setActive to throw a ClerkRuntimeError when an organization slug is provided but no matching organization exists for the user. Also adds test coverage for the invalid-slug rejection (with a duplicate test instance added).

Changes

Cohort / File(s) Summary
Core logic — setActive validation
packages/clerk-js/src/core/clerk.ts
Inserts a validation path in Clerk.setActive that checks for an explicitly provided organization slug and throws a ClerkRuntimeError with a descriptive message and specific error code if no matching organization is found. Executes before existing forceOrganizationSelection and last-active updates.
Tests — invalid slug behavior
packages/clerk-js/src/core/__tests__/clerk.test.ts
Adds a test asserting setActive rejects with the exact error message when given an invalid organization slug. The invalid-slug test appears twice (duplicated) within the same describe block.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Clerk.setActive
    participant OrgStore
    participant Error

    Caller->>Clerk.setActive: setActive({ organization: "invalid-org-slug" })
    Clerk.setActive->>OrgStore: lookup organization by slug
    OrgStore-->>Clerk.setActive: not found

    rect rgb(255, 230, 230)
    Note over Clerk.setActive,Error: NEW validation path
    Clerk.setActive->>Error: throw ClerkRuntimeError("Unable to find organization with slug \"invalid-org-slug\"...")
    Error-->>Caller: reject with error
    end

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Localized changes in two files; logic is a single validation branch and matching tests.
  • Areas needing extra attention:
    • Exact error message and code consistency in clerk.ts.
    • Removal or consolidation of the duplicated test in clerk.test.ts.

Poem

🐇 A slug once lost in hush and fog,
Now hops aloud through code and log.
"Not found!" it cries with rhyming cheer,
No silence left — the path is clear.
🥕

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'fix(clerk-js): Fix silent failure with setActive org slug' directly and clearly summarizes the main change. It identifies the package (clerk-js), the type of change (fix), and the specific issue being addressed (silent failure with setActive org slug). The title is concise and specific enough for teammates to understand the primary change when scanning history.
Linked Issues check ✅ Passed The code changes directly address the requirements specified in linked issue USER-3777. The PR adds validation in clerk.ts that throws a ClerkRuntimeError when an invalid org_slug is provided to setActive, and adds test cases in clerk.test.ts to verify this error handling. This transforms the previously silent failure into an explicit error comparable to the org_id case, which matches the stated objective of ensuring consistent error behavior.
Out of Scope Changes check ✅ Passed All changes in this pull request are directly related to fixing the silent failure issue with setActive and org_slug validation. The modifications to clerk.ts implement the error handling logic, and the test additions in clerk.test.ts validate this behavior. There are no unrelated changes or alterations to other functionality outside the scope of addressing the silent failure.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment
  • [ ] Commit unit tests in branch cursor/USER-3777-fix-silent-failure-with-setactive-org-slug-fe0b

📜 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 1e7a51d23d80ed5f748d04ce7f451a3c3dd1a3d9 and 022593ddbf8f25770310254ab98549d9af0b1f7e.

📒 Files selected for processing (2)
  • packages/clerk-js/src/core/__tests__/clerk.test.ts (1 hunks)
  • packages/clerk-js/src/core/clerk.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/clerk-js/src/core/tests/clerk.test.ts
  • packages/clerk-js/src/core/clerk.ts
⏰ 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). (28)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (nextjs, chrome, 16)
  • GitHub Check: Integration Tests (quickstart, chrome, 15)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome, 16)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: Static analysis
  • 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.

coderabbitai[bot] avatar Nov 03 '25 15:11 coderabbitai[bot]

Open in StackBlitz

@clerk/agent-toolkit

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

commit: 022593d

pkg-pr-new[bot] avatar Nov 03 '25 16:11 pkg-pr-new[bot]

Found 18 test failures on Blacksmith runners:

Test View Logs
[chrome] › integration/tests/
components.test.ts:102:9 › component smoke tests @generic › long-running--react.vite.wi
thEmailCodes › CreateOrganization supports fallback
View Logs
[chrome] › integration/tests/elements/
next-sign-in.test.ts:134:7 › Next.js Sign-In Flow @elements › long-running--elements.ne
xt.appRouter › can reset password
View Logs
[chrome] › integration/tests/elements/
otp.test.ts:196:9 › OTP @elements › long-running--elements.next.appRouter › Type: segme
nted-otp › should forward-delete char when pressing delete
View Logs
[chrome] › integration/tests/
handshake.test.ts:863:7 › Client handshake @generic › External visit - new devbrowser
View Logs
[chrome] › integration/tests/
pricing-table.test.ts:221:7 › pricing table @billing › long-running--withBilling.next.a
ppRouter › user is prompted to add email before checkout
View Logs
[chrome] › integration/tests/
pricing-table.test.ts:588:9 › pricing table @billing › long-running--withBilling.next.a
ppRouter › in UserProfile › adds payment method via checkout and resets stripe setup in
tent after failed payment
View Logs
[chrome] › integration/tests/
pricing-table.test.ts:625:9 › pricing table @billing › long-running--withBilling.next.a
ppRouter › in UserProfile › displays notice then plan cannot change
View Logs
[chrome] › integration/tests/
pricing-table.test.ts:658:9 › pricing table @billing › long-running--withBilling.next.a
ppRouter › in UserProfile › adds two payment methods and sets the last as default
View Logs
[chrome] › integration/tests/
pricing-table.test.ts:80:9 › pricing table @billing › long-running--withBilling.vue.vit
e › when signed in flow › when signed in, clicking get started button opens checkout dr
awer and shows free plan as active
View Logs
[chrome] › integration/tests/
sign-in-flow.test.ts:101:7 › sign in flow @generic @nextjs › long-running--next.appRout
er.withEmailCodes › can reset password
View Logs
[chrome] › integration/tests/
sign-in-flow.test.ts:101:7 › sign in flow @generic @nextjs › long-running--next.appRout
er.withEmailCodes › can reset password
View Logs
[chrome] › integration/tests/
sign-in-flow.test.ts:101:7 › sign in flow @generic @nextjs › long-running--next.appRout
er.withEmailCodes › can reset password
View Logs
[chrome] › integration/tests/
sign-in-flow.test.ts:101:7 › sign in flow @generic @nextjs › long-running--next.appRout
er.withEmailCodes › can reset password
View Logs
[chrome] › integration/tests/
sign-in-flow.test.ts:101:7 › sign in flow @generic @nextjs › long-running--react.vite.w
ithEmailCodes › can reset password
View Logs
[chrome] › integration/tests/
sign-in-or-up-flow.test.ts:115:9 › sign-in-or-up flow @nextjs › long-running--next.appR
outer.withSignInOrUpFlow › sign-in › can reset password
View Logs
[chrome] › integration/tests/
sign-in-or-up-flow.test.ts:115:9 › sign-in-or-up flow @nextjs › long-running--next.appR
outer.withSignInOrUpFlow › sign-in › can reset password
View Logs
[chrome] › integration/tests/
sign-in-or-up-flow.test.ts:115:9 › sign-in-or-up flow @nextjs › long-running--next.appR
outer.withSignInOrUpFlow › sign-in › can reset password
View Logs
[setup] › integration/tests/
global.setup.ts:7:6 › start long running apps ─────────────────────
View Logs


Fix in Cursor

blacksmith-sh[bot] avatar Nov 03 '25 16:11 blacksmith-sh[bot]