Skip to content

fix(api): send a signed-out browser to sign in from a connect link - #9819

Merged
Kitenite merged 2 commits into
mainfrom
superset/super-3480-ahrefs-connect-unauthorized-44e763cc
Nov 16, 2026
Merged

Kitenite merged 2 commits into
mainfrom
superset/super-3480-ahrefs-connect-unauthorized-44e763cc

Conversation

@harshithmullapudi

@harshithmullapudi harshithmullapudi commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

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) opens GET /api/connectors/ahrefs_mcp/connect?organizationId=…&method=oauth2&plugin=ahrefs in the system browser. When that browser has no Paradev session cookie for the API, requireOrgMember returns a bare 401 {"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) and superset plugins connect open 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 requireOrgMember finds no session, it now redirects to <web>/sign-in?redirect=<connect URL> instead of returning 401. <web> is the NEXT_PUBLIC_WEB_URL twin on the request's own root domain (review follow-up), because the session cookie is scoped to one root domain and the API keeps api.superset.sh while the web moves to paradev.com. The sign-in page already accepts redirects back to the API origin (resolveCallbackUrl with the API in its trusted origins, plus better-auth trustedOrigins). 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 requireOrgMember is 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:

  • Before: Plugins → Ahrefs → Install → Continue to Ahrefs. The system browser shows {"error":"Unauthorized"} and the API log shows GET /api/connectors/ahrefs_mcp/connect… 401.
  • After: same steps, browser signed out. The connect route 302s to sign-in, sign-in returns to the route, which 302s to app.ahrefs.com/web/oauth/authorize with our DCR client and a signed state. Ahrefs shows its Cloudflare check, then its sign-in page.
  • Unit test requireOrgMember.test.ts fails on the old code and passes now. apps/api: 261 tests pass, tsc --noEmit and 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

  • On hosts outside our own domains (for example *.vercel.app previews), 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.
  • A browser signed in to an account that is not in the org still gets a raw JSON 403 from the same route. That's the same kind of dead end, but out of scope here (raised in review).

Unrelated observation

  • The Connect dialog briefly titles itself "Connect ahrefs_mcp" (the slug) while the connector loads.

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

  • Bug Fixes
    • Unauthenticated requests to OAuth connector URLs now redirect to the sign-in page instead of returning an error response.
    • The redirect preserves the original connector URL so users can return to it after signing in.
    • The sign-in page uses a web domain matching the request when available, with the configured web URL as a fallback.

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.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

requireOrgMember now redirects requests without a session user to a sign-in page. It selects a configured web URL based on the request hostname when available, otherwise uses the default web URL, and includes the original request URL in the redirect.

Changes: Connector authentication

Layer / File(s) Summary
Sign-in redirect behavior
apps/api/src/lib/integrations/requireOrgMember.ts, apps/api/src/lib/integrations/requireOrgMember.test.ts
When a session has no user, requireOrgMember returns a 302 redirect to /sign-in. It uses a configured web URL with a matching own-domain root when available, otherwise the default web URL. Tests verify the destination and original request URL for two API hostnames.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related PRs

  • ParadevAI/Paradev#8899: Changes how signed-in visits to /sign-in or /sign-up handle redirect targets, which relates to completing the return flow started by this PR.
  • ParadevAI/Paradev#9702: Changes the browser sign-in host and handling of the sign-in redirect parameter, which relates to the host and return destination selected here.
  • ParadevAI/Paradev#9687: Changes authentication and integration callback domains and continuation handling, which relates to the cross-domain sign-in return flow.

Suggested reviewers: saddlepaddle

Merge Risk: Minimal · up to 7ebb0

Signed-out users who open a connect link are now sent to sign-in and then back to the connect route instead of seeing a 401 JSON error. No concrete merge-blocking risk remains in the supplied evidence.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a signed-out browser opening a connect link is now sent to sign-in. The raw summary confirms requireOrgMember now redirects unauthenticated requests with a 302 to sign…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the repository template closely. It has the 'What & why' content (root cause, fix, and a linked issue SUPER-3480), the 'How I tested it' content (desktop dev app verification o…
Full details: Title check

Explanation

The title names the main change: a signed-out browser opening a connect link is now sent to sign-in. The raw summary confirms requireOrgMember now redirects unauthenticated requests with a 302 to sign-in instead of returning 401, and the title follows conventional commit format. The title is specific and matches the changeset.

Full details: Description check

Explanation

The description follows the repository template closely. It has the 'What & why' content (root cause, fix, and a linked issue SUPER-3480), the 'How I tested it' content (desktop dev app verification over CDP with before/after results, unit test results, and tsc/biome results), and known limitations. The template's Checklist section is missing entirely, so it is not confirmed that the PR title follows conventional commits (the PR title is PR #9819, 'fix(api): send a signed-out browser to sign in from a connect link', which appears to match the format), that lint and typecheck pass in CI terms, that maintainer edits are allowed on fork PRs, or that the CLA was signed. The 'How I tested it' section also does not include screenshots inline, though it points to a Paradev page with before/after screenshots and a video. The content is substantive and mostly complete, so the check passes, but the checklist gap should be noted.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

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: 4f2265e4-d1a0-4de0-8636-8e69847d16ab
Commits

Reviewing files that changed from the base of the PR and between d097f50 and 7ebb005.

Files selected for processing: 2

  • apps/api/src/lib/integrations/requireOrgMember.test.ts
  • apps/api/src/lib/integrations/requireOrgMember.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch

Thank you for your contribution! 🎉

Copy link
Copy Markdown
Contributor

Review verdict: looks good. The fix is small and in the right place. All 8 callers of requireOrgMember are GET routes that a browser opens, and none of them reads the response as JSON.

Follow-ups (not blocking):

  • apps/api/src/lib/integrations/requireOrgMember.ts:24: the sign-in host comes from NEXT_PUBLIC_WEB_URL. If the web moves to paradev.com while the API stays on api.superset.sh (packages/shared/src/app-identity.ts:31), the cookie does not reach the API and a signed-in user lands on /. Before the domain move, pick the web twin on the request's root domain, or let the web proxy follow trusted absolute redirects.
  • apps/api/src/lib/integrations/requireOrgMember.ts:40-45: a browser signed in to an account outside the org still gets raw JSON 403. This is the same kind of dead end as SUPER-3480; it is out of scope here.

Verified at d097f50a: apps/api has 261 tests passing; the new test fails on the old code (401 instead of 302); tsc and biome pass. With curl, the local API and the PR's preview API both 302 to /sign-in?redirect=<connect URL>. I did not run the full browser round trip: the preview web is behind Vercel protection, and there is no local DB.

Report: https://app.superset.sh/page/pr-9819-review-connect-link-sign-in-redirect-h8k5br

@expo

expo Bot commented Nov 16, 2026

Copy link
Copy Markdown

🎉 Your workflow run has finished!

Check out the details below.


Builds

ID Platform Status Actions
6f087dd iOS ✅ Success (logs) Install Download
Open QR Code Install QR code for build 6f087ddd-dd3a-4847-905b-035b16ed9ae7

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).

This branch was previously deployed

1 inactive deployment
preview — 7ebb005d Deployed Nov 16, 2026 by Kitenite via Cleanup Preview Resources #5662
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

github GitHub-sourced work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants