Skip to content

fix(ui): Default OAuthConsent org selection to last active organization#8362

Merged
wobsoriano merged 1 commit intomainfrom
kylemac/oauth-consent-last-active-org
Apr 20, 2026
Merged

fix(ui): Default OAuthConsent org selection to last active organization#8362
wobsoriano merged 1 commit intomainfrom
kylemac/oauth-consent-last-active-org

Conversation

@kylemac
Copy link
Copy Markdown
Contributor

@kylemac kylemac commented Apr 20, 2026

Description

The <OAuthConsent /> org picker currently defaults to whichever org the API returns first. This change seeds the default from clerk.session?.lastActiveOrganizationId so users consent on behalf of the org they were most recently working in, falling back to the first membership when the last active org is null, doesn't match any membership, or was deleted. Read via the already-in-scope useClerk() (no new hook, no re-renders from useSession), and the existing render guards keep the no-memberships case unchanged.

Added three test cases covering the match, no-match, and null paths, plus a @clerk/ui patch changeset.

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:

The OAuthConsent org picker now preselects the user's last active
organization when it matches a membership, falling back to the first
membership otherwise. Users typically want to consent on behalf of the
org they were most recently working in, not whichever one the API
returned first.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 20, 2026

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

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Apr 20, 2026 3:40pm

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 20, 2026

🦋 Changeset detected

Latest commit: a0701c4

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

This PR includes changesets to release 2 packages
Name Type
@clerk/ui Patch
@clerk/chrome-extension 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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: d709849e-f051-4aaa-aca2-dcd80c62dbc9

📥 Commits

Reviewing files that changed from the base of the PR and between d7758e3 and a0701c4.

📒 Files selected for processing (3)
  • .changeset/oauth-consent-last-active-org.md
  • packages/ui/src/components/OAuthConsent/OAuthConsent.tsx
  • packages/ui/src/components/OAuthConsent/__tests__/OAuthConsent.test.tsx

📝 Walkthrough

Walkthrough

The changes implement a feature for the <OAuthConsent /> component to default the organization selection to the user's last active organization. The implementation derives a defaultOrg value from clerk.session.lastActiveOrganizationId by matching it against available organization options, falling back to the first membership if no match exists. The effectiveOrg computation is updated to use selectedOrg when set, otherwise the new defaultOrg. A changeset entry documents this patch-level change, and three test cases validate the organization selection behavior under different scenarios (matching last active org, non-matching ID, and null ID).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: defaulting OAuthConsent org selection to the user's last active organization.
Description check ✅ Passed The description is directly related to the changeset, explaining the motivation, implementation approach, and test coverage for the org selection default behavior change.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 20, 2026

Open in StackBlitz

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8362

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/react

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

@clerk/react-router

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8362

@clerk/upgrade

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

@clerk/vue

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

commit: a0701c4

Copy link
Copy Markdown
Member

@wobsoriano wobsoriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Kyle! Should we also set the selected organization as the active one? If yes, I can open a follow-up PR.

@wobsoriano wobsoriano merged commit 0744a0b into main Apr 20, 2026
88 of 102 checks passed
@wobsoriano wobsoriano deleted the kylemac/oauth-consent-last-active-org branch April 20, 2026 16:17
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