From 949413d98e0cfe7b5b9b4597cdfd0c467f0b8a87 Mon Sep 17 00:00:00 2001 From: Prasanna721 <106952318+Prasanna721@users.noreply.github.com> Date: Tue, 16 Jun 2026 21:19:06 +0000 Subject: [PATCH] fix mcp consent org restore (#1126) Stops Nova's saved active org from overriding the org picked on the MCP OAuth consent page. - skips localStorage org restoration on `/oauth/consent` - keeps normal Nova org restore behavior everywhere else Testing: - `bunx biome check --write packages/lib/auth-context.tsx` - `bun run --filter @repo/web lint` passes with existing warnings - `bunx tsc --noEmit --project apps/web/tsconfig.json` fails on existing unrelated type errors outside this change --- packages/lib/auth-context.tsx | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/lib/auth-context.tsx b/packages/lib/auth-context.tsx index 84b095b0..d3d0bedb 100644 --- a/packages/lib/auth-context.tsx +++ b/packages/lib/auth-context.tsx @@ -111,6 +111,11 @@ export function AuthProvider({ children }: { children: ReactNode }) { const run = async () => { try { + // OAuth consent owns org selection for the authorization transaction. + const shouldRestoreSavedOrg = + typeof window === "undefined" || + window.location.pathname !== "/oauth/consent" + if (orgs.length === 0) { if (!cancelled) setOrg(null) return @@ -130,19 +135,21 @@ export function AuthProvider({ children }: { children: ReactNode }) { return } - const savedSlug = localStorage.getItem(STORAGE_KEY) - if (savedSlug) { - const match = orgs.find((o) => o.slug === savedSlug) - if (match) { - if (activeOrgId === match.id) { - const full = await authClient.organization.getFullOrganization() - if (!cancelled) setOrg(full?.data ?? null) - } else { - await setActiveOrg(savedSlug) + if (shouldRestoreSavedOrg) { + const savedSlug = localStorage.getItem(STORAGE_KEY) + if (savedSlug) { + const match = orgs.find((o) => o.slug === savedSlug) + if (match) { + if (activeOrgId === match.id) { + const full = await authClient.organization.getFullOrganization() + if (!cancelled) setOrg(full?.data ?? null) + } else { + await setActiveOrg(savedSlug) + } + return } - return + localStorage.removeItem(STORAGE_KEY) } - localStorage.removeItem(STORAGE_KEY) } if (activeOrgId) {