PR #9819 review: send a signed-out browser to sign in from a connect link

PR #9819 · Review workspace · author harshithmullapudi · reviewed at d097f50a · 2026-11-16

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

Minor · follow-up

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.

Nit · out of scope

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:

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:

Questions for the author

Test / CI notes

All at d097f50ab1011bb4668dd0657c14316d7e0edcbd (PR head):