Repository navigation
fix(api): send a signed-out browser to sign in from a connect link - #9819
Conversation
The desktop's Connect button (useConnector.openOAuth), the agent proxy's
connect links and `superset plugins connect` all open
/api/connectors/<slug>/connect in the system browser. When that browser
had no Paradev session, requireOrgMember answered with a bare
{"error":"Unauthorized"} 401, so the user saw only that JSON and the
connect stopped before any OAuth step. Customers hit it first with the
new Ahrefs plugin (SUPER-3480).
A signed-out request now goes to the web sign-in page with the connect
URL as `redirect`. Sign-in already accepts redirects to the API origin
(resolveCallbackUrl, better-auth trustedOrigins), so after signing in the
browser comes back to the connect route and goes on to the provider.
The fix is on the API so released desktop and CLI builds get it too.
Every caller of requireOrgMember is a GET route reached by browser
navigation; none expects a JSON 401.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
|
Review verdict: looks good. The fix is small and in the right place. All 8 callers of Follow-ups (not blocking):
Verified at Report: https://app.superset.sh/page/pr-9819-review-connect-link-sign-in-redirect-h8k5br |
Review follow-up. The session cookie is scoped to one root domain, and the API keeps api.superset.sh while the web moves to paradev.com. Sending an api.superset.sh connect to sign in on app.paradev.com would set a cookie that never reaches the API, so the user would land on the web home instead of finishing the connect. Sign-in now uses the NEXT_PUBLIC_WEB_URL twin on the request's own root domain, and falls back to NEXT_PUBLIC_WEB_URL for hosts outside our own domains (localhost, previews).
Fixes SUPER-3480: Connect on the Ahrefs plugin shows
{"error":"Unauthorized"}.Root cause
The problem is in our connect route, not in Ahrefs or OAuth. The desktop's Continue to Ahrefs (
useConnector.openOAuth) opensGET /api/connectors/ahrefs_mcp/connect?organizationId=…&method=oauth2&plugin=ahrefsin the system browser. When that browser has no Paradev session cookie for the API,requireOrgMemberreturns a bare401 {"error":"Unauthorized"}and the flow stops before discovery, registration or the authorize step.The route is shared by every OAuth connector. The agent proxy's connect links (
resolve-target.ts) andsuperset plugins connectopen it the same way. Ahrefs is just the first new plugin a customer tried from a signed-out browser. The older integrations don't hit this because the desktop opens their web page (/integrations/linear), and that page signs the browser in first.Fix
When
requireOrgMemberfinds no session, it now redirects to<web>/sign-in?redirect=<connect URL>instead of returning 401.<web>is theNEXT_PUBLIC_WEB_URLtwin on the request's own root domain (review follow-up), because the session cookie is scoped to one root domain and the API keepsapi.superset.shwhile the web moves to paradev.com. The sign-in page already accepts redirects back to the API origin (resolveCallbackUrlwith the API in its trusted origins, plus better-authtrustedOrigins). So after signing in, the browser comes back to the connect route and goes on to the provider.The fix is in the API so that released desktop and CLI builds get it without a new release. Every caller of
requireOrgMemberis a GET route reached by browser navigation; none expects a JSON 401.Verification
Desktop dev app, driven over CDP, with the system browser on the same display:
{"error":"Unauthorized"}and the API log showsGET /api/connectors/ahrefs_mcp/connect… 401.app.ahrefs.com/web/oauth/authorizewith our DCR client and a signed state. Ahrefs shows its Cloudflare check, then its sign-in page.requireOrgMember.test.tsfails on the old code and passes now.apps/api: 261 tests pass,tsc --noEmitand biome pass.Not verified: the Ahrefs steps after its sign-in (consent, token exchange, tool call). They need a real Ahrefs Lite+ account, which I don't have. Ahrefs' DCR (
/mcp/register) accepts our registration body as-is.Known limitations / follow-ups
*.vercel.apppreviews), web and API can't share a cookie. A browser already signed in on the web then lands on/instead of finishing the connect. It is not a loop.403from the same route. That's the same kind of dead end, but out of scope here (raised in review).Unrelated observation
Evidence
Paradev page with repro steps, root cause, before/after screenshots and a video of the fix: https://app.superset.sh/page/super-3480-ahrefs-connect-shows-unauthorized-vawdbt
Summary by CodeRabbit