PR #9819 review: send a signed-out browser to sign in from a connect link
Summary
The OAuth connect routes on the API (/api/connectors/[connector]/connect, /api/integrations/*/connect, /api/github/install) all start with requireOrgMember. When the system browser had no Paradev session, this returned a bare 401 {"error":"Unauthorized"}. That is what customers saw on "Continue to Ahrefs" (SUPER-3480). Now it sends a 302 to ${NEXT_PUBLIC_WEB_URL}/sign-in?redirect=<connect URL>. The sign-in page already trusts the API origin, so after sign-in the browser comes back and the flow continues. The fix is on the server only, so released desktop and CLI builds get it with no new release.
Verdict
looks good The change is small and in the right place, and all 8 callers are browser-navigated GET routes. I found nothing that blocks it. The two notes below are follow-ups.
Findings
apps/api/src/lib/integrations/requireOrgMember.ts:24: the sign-in host comes from env.NEXT_PUBLIC_WEB_URL, so the redirect only completes when web and API share a cookie domain. The PR calls this a preview-only limitation, but it is also the plan for the rename: packages/shared/src/app-identity.ts:31 says "The API keeps its host when the root domain changes". If the web moves to app.paradev.com while the API stays on api.superset.sh, sign-in sets a cookie the API cannot read. The connect route then redirects again, and the web proxy (apps/web/src/proxy.ts, safeRedirectUrl) sends the now-signed-in user to /. Nothing fails loudly; the flow just stops.
Fix (later): before the domain move, pick the web twin on the same root as request.url (via withOwnDomainTwins). Or let the web proxy follow trusted absolute redirects with resolveCallbackUrl, as the sign-in page already does. This affects the web-initiated integration flows the same way, so it is a domain-move item, not something this PR adds.
apps/api/src/lib/integrations/requireOrgMember.ts:40-45: a browser signed in to a different account (not a member of the org) still gets a raw JSON 403 {"error":"User is not a member of this organization"}. This is the same kind of dead end SUPER-3480 reported, and it is likely when the system browser has a personal account signed in. Fix (later): redirect to a web page that names the signed-in account and offers to switch.
Checked and fine:
- All 8 callers (
connectors/[connector]/connect,integrations/{google,linear,microsoft-teams,notion,sentry,slack}/connect,github/install) returnmemberunchanged when it is aResponse. No caller fetches these routes as JSON: the CLI (packages/cli/src/lib/plugins/connect.ts:134), the agent proxy (packages/trpc/src/router/plugins/proxy/resolve-target.ts:109) and the desktopuseConnectorall build a URL for a browser to open. The JSON-401 rule inapps/web/src/proxy.ts(#7072) is for JSON clients, so it does not apply here. - Open redirect: the
redirectvalue is the API's ownrequest.url, and the sign-in page checks it again withresolveCallbackUrlagainst[webUrl, NEXT_PUBLIC_API_URL]plus domain twins. - The test uses
test/stub.ts, which restoresauth.api.getSessionafter the file finishes. It does not usemock.module, so it follows the AGENTS.md test rules.
Evidence
Surface: API only (no UI in the diff). The commands and their output are below.
1. Local API (next dev on :3001 at PR head, placeholder env, no cookie). All three route families now 302 to sign-in, with the full connect URL as redirect:
$ curl -sS -D - -o /dev/null 'http://localhost:3001/api/connectors/ahrefs_mcp/connect?organizationId=org-1&method=oauth2&plugin=ahrefs' HTTP/1.1 302 Found location: http://localhost:3000/sign-in?redirect=http%3A%2F%2Flocalhost%3A3001%2Fapi%2Fconnectors%2Fahrefs_mcp%2Fconnect%3ForganizationId%3Dorg-1%26method%3Doauth2%26plugin%3Dahrefs $ curl -sS -D - -o /dev/null 'http://localhost:3001/api/integrations/linear/connect?organizationId=org-1' HTTP/1.1 302 Found location: http://localhost:3000/sign-in?redirect=http%3A%2F%2Flocalhost%3A3001%2Fapi%2Fintegrations%2Flinear%2Fconnect%3ForganizationId%3Dorg-1 $ curl -sS -D - -o /dev/null 'http://localhost:3001/api/github/install?organizationId=org-1' HTTP/1.1 302 Found location: http://localhost:3000/sign-in?redirect=http%3A%2F%2Flocalhost%3A3001%2Fapi%2Fgithub%2Finstall%3ForganizationId%3Dorg-1
2. The PR's Vercel preview API shows the same behaviour on a deployed build:
$ curl -sS -D - -o /dev/null 'https://api-pr-9819-superset.vercel.app/api/connectors/ahrefs_mcp/connect?organizationId=org-1&method=oauth2&plugin=ahrefs' HTTP/2 302 location: https://web-pr-9819-superset.vercel.app/sign-in?redirect=https%3A%2F%2Fapi-pr-9819-superset.vercel.app%2Fapi%2Fconnectors%2Fahrefs_mcp%2Fconnect%3F...
3. The sign-in page's resolveCallbackUrl accepts the redirect back to the API, including the domain twin:
trusted API: http://localhost:3001/api/connectors/ahrefs_mcp/connect?organizationId=org-1&method=oauth2&plugin=ahrefs prod pair: https://api.superset.sh/api/connectors/x/connect?organizationId=o domain twin: https://api.paradev.com/api/connectors/x/connect?organizationId=o
Not verified:
- The full browser round trip (sign in, return to connect, go on to Ahrefs).
web-pr-9819-superset.vercel.appis behind Vercel deployment protection ("Log in to Vercel"), andapi.pr-9819.paradev.comtimed out from this sandbox. A local web + API stack needs a database and OAuth secrets, and this workspace has no.env. The author reports doing this round trip in the desktop dev app over CDP. - Ahrefs consent and token exchange (needs an Ahrefs Lite+ account, as the PR says).
Questions for the author
- Is the root-domain move planned to keep web and API on the same cookie domain? If not, should the sign-in host follow the request's root before the move (finding 1)?
- Do you want a ticket for the "signed in as the wrong account" 403 case (finding 2)? It is the next dead end in this flow.
Test / CI notes
All at d097f50ab1011bb4668dd0657c14316d7e0edcbd (PR head):
bun testinapps/api: 261 pass, 0 fail.- New test against the old code (with the 401 put back locally): fails with
Expected: 302 / Received: 401. With the PR code it passes. So it is a real regression test. tsc --noEmitinapps/api: exit 0.biome check apps/api/src/lib/integrations/: clean.- GitHub CI: Lint, Typecheck, Test, Sherif, Version Sync, Build CLI, and the API/Web/Docs/Marketing preview deploys all pass. CodeRabbit was still running when I checked.