Skip to content

fix: offer to switch account when a link is for another organization, keep JSON for API clients - #9827

Closed
Kitenite wants to merge 1 commit into
superset/super-3480-follow-up-guide-re-sign-in-on-f4ab0620from
kitenite/fix/browser-wrong-account-prompt
Closed

Kitenite wants to merge 1 commit into
superset/super-3480-follow-up-guide-re-sign-in-on-f4ab0620from
kitenite/fix/browser-wrong-account-prompt

Conversation

@Kitenite

@Kitenite Kitenite commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Follow-up to SUPER-3480. Stacked on #9823, which is stacked on #9819. This PR targets #9823's branch, so the diff shows only this change.

Why

#9819 and #9823 send a signed-out browser from a connect link to sign in. Three gaps were left:

  1. Wrong account. A browser signed in to an account that is not in the link's organization still got a raw {"error":"User is not a member of this organization"} 403. This applies to all 8 connect routes that use requireOrgMember. The Slack link route had the same dead end, as plain text.
  2. API clients. fix(api): send a signed-out browser to sign in from a connect link #9819 made requireOrgMember redirect every request without a session, so a JSON client got a 302 to an HTML page instead of a 401.
  3. Other browser links. Document file links (/api/{projects,tasks}/…/files/…) showed a bare Unauthorized. The sign-in page explained an expired session only for connector links.

What

  • apps/api/src/lib/browserAuth.ts generalizes fix(api): send a signed-out browser to sign in from a connect link #9819's signInUrl. signedOut(request, apiResponse) and wrongAccount(request, apiResponse) redirect a browser navigation and return apiResponse to anything else. A browser navigation has text/html in Accept (the same parser as the domain move, now exported as acceptsHtml) and no Authorization, x-api-key or x-trpc-source header. The web page is still picked on the request's own root domain, and reason=session_expired behaves as before.
  • requireOrgMember, /api/integrations/slack/link and the two file routes use these helpers.
  • New /switch-account page (web). It says "You are signed in as {email}. This account is not a member of the organization this link is for." It names the connector when the link is a connector connect link, reusing feat: guide signed-out, expired and wrong-account browsers from any API link #9823's connectSignInContext. Sign in with another account signs out and goes to /sign-in?redirect=<link>, so the flow continues after sign-in. A signed-out visitor goes straight to sign-in. The page does not show the organization's name, because the visitor is not a member.
    • The return path goes through the existing resolveCallbackUrl (web origin or the API and its own-domain twins), so it cannot be used for an open redirect.
    • It is a public route in proxy-routes, and it is retained on the legacy host in domain-move. It must sign out the session on the root domain the API saw, so a move to paradev.com would act on the wrong cookie.
  • Sign-in page. A non-connector link with reason=session_expired now shows "Your Paradev session in this browser has expired. Sign in again to continue." instead of "Sign in to continue to Paradev".
  • resolveCallbackUrl and connectSignInContext moved to apps/web/src/app/utils/, because the sign-in page and /switch-account both use them now. The files did not change.
  • 5 new strings, translated in all 17 locales.

Audit: browser-navigable routes

"API client" means no text/html Accept, or an Authorization/x-api-key/x-trpc-source header. "Before" is main + #9819 + #9823.

Route (a) no session (b) invalid / expired cookie (c) wrong account API client
GET /api/connectors/<slug>/connect sign-in (#9819) sign-in + expired copy (#9823) was 403 JSON → /switch-account was 302 → 401/403 JSON again
GET /api/integrations/{linear,google,slack,notion,sentry,microsoft-teams}/connect, GET /api/github/install sign-in (#9819) sign-in; expired copy now shown was 403 JSON → /switch-account was 302 → 401/403 JSON again
GET /api/integrations/slack/link sign-in (now on the request's root domain) same, with expired copy was 403 text → /switch-account 401 / 403 text
GET /api/{projects,tasks}/<id>/files/<file> was 401 text → sign-in was 401 text → sign-in + expired copy 404 (unchanged, so the file's existence is not revealed) 401 text
Connector + legacy OAuth callbacks (/api/connectors/callback/*, /api/integrations/*/callback, /api/github/callback) Not session based. The state cookie + signed state are re-checked, and a failure redirects to the web page with ?error=… same membership re-checked; ?error=unauthorized on the web page n/a
GET /api/github/user/callback HTML page (state carries identity) same same n/a
GET /api/auth/desktop/connect starts sign-in (no session needed) same n/a n/a
GET /auth/integration-connect (web, legacy) sign-in, then continues same continues to the API connect route, which now shows /switch-account n/a
/oauth/consent, /cli/auth/code, web pages (/connect/<slug>, /integrations/*, /plugins/*) proxy → sign-in with return path same Uses the active org, so no org id in the link to mismatch. Consent lets the user pick n/a
/accept-invitation/<id> The token-based accept works without a session same the invitation's own error message n/a
GET /api (agent discovery) 401 JSON with a WWW-Authenticate hint (left as is, for agents)

Not changed: a missing organizationId still returns 400 JSON. That is a malformed link, not a session problem.

Verification

  • requireOrgMember.test.ts: new tests for wrong account (browser → /switch-account), member passes, and API clients (no Accept, JSON Accept, Authorization, x-trpc-source) getting 401/403 JSON for both no session and wrong account. 5 of them fail on feat: guide signed-out, expired and wrong-account browsers from any API link #9823's code (checked by restoring the old file) and pass now.
  • apps/api: all pass except 3 Slack event tests (webidl.util.markAsUncloneable). These fail the same way on feat: guide signed-out, expired and wrong-account browsers from any API link #9823's branch without this change. apps/web 127 pass, packages/shared domain-move tests pass. bun run typecheck exit 0, bun run lint:fix clean, and bun run check:i18n passes.
  • End to end on the dev stack (api :8681, web :8680) in headless Chrome with a fresh profile, driven over CDP:
    • no cookie → Ahrefs connect link → "Sign in to connect Ahrefs"
    • invalid session cookie → Linear connect link → "Welcome back. Your Paradev session in this browser has expired. Sign in again to continue." (before: "Sign in to continue to Paradev")
    • signed in as a new user outside the org → Ahrefs connect link. Before: {"error":"User is not a member of this organization"}. After: "Switch account to connect Ahrefs. You are signed in as outsider-…@example.com…"
    • Sign in with another account → sign-in page for the same link → sign in as the org's admin → app.ahrefs.com/web/oauth/authorize with our client and signed state. The flow continues.
    • curl checks: a JSON client gets 401 {"error":"Unauthorized"}. A browser Accept plus Authorization also gets 401. Before this change, a JSON client got a 302.
  • Not tested on production domains. The root-domain choice and the domain-move retention are covered by unit tests only.

Summary by cubic

Connect links in a browser now lead to sign-in or, when the signed-in account isn't in the link's organization, a new "switch account" page; API clients keep their 401/403 JSON responses.

  • Warns a browser signed in to the wrong account to switch instead of showing a raw {"error":"User is not a member of this organization"} 403.
  • Returns 401/403 JSON to API clients (no text/html in Accept, or with Authorization, x-api-key, or x-trpc-source) instead of a 302 redirect.
  • Applies to all requireOrgMember connect routes, the Slack link route, and the project/task document file links, which were showing bare Unauthorized text.
  • The sign-in page now explains that the Paradev session expired for non-connector links as well as connector links.
  • /switch-account stays on the legacy host during the domain move because it signs out that host's session cookie, and it is added as a public proxy route with redirect validated by resolveCallbackUrl.
  • resolveCallbackUrl and connectSignInContext moved from the sign-in route into shared apps/web/src/app/utils/.

Written for commit 68e51cc. Summary will update on new commits.

View guided diff Turn on auto-fix

…ep JSON for API clients

requireOrgMember, the Slack link route and the document file routes now
answer a browser navigation with a page: sign in when there is no usable
session, and /switch-account when the signed-in user is not in the link's
organization. Requests without text/html in Accept, or with Authorization,
x-api-key or x-trpc-source, get the JSON 401/403 they got before #9819.

The sign-in page also says when a session expired for links that are not a
connector. /switch-account stays on the legacy host during the domain move
because it acts on that host's session cookie.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: de2a379c-0ede-404e-b8bc-f2ac1b43bb85

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Preview Deployment

🔗 Preview Links

Service Status Link
Neon Database (Neon) ✅ View Branch
Vercel API (Vercel) ✅ Open Preview
Vercel Web (Vercel) ✅ Open Preview
Vercel Agents Web (Vercel) ➖ Not set up
Vercel Marketing (Vercel) ✅ Open Preview
Vercel Docs (Vercel) ✅ Open Preview

Preview updates automatically with new commits

@Kitenite

Copy link
Copy Markdown
Member Author

Superseded by #9823, which now covers every case here (no session, expired session, wrong account, API clients, file links, the Slack link) and is merged.

@Kitenite Kitenite closed this Nov 16, 2026

This branch was previously deployed

1 inactive deployment
preview — 68e51cc9 Deployed Nov 16, 2026 by Kitenite via Deploy Marketing #14815
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant