Skip to content

Open-source SEO, GEO, and marketing skills for AI agents.

fix(notfair-cmo): land OAuth callback back on the connections page

Yuting Zhong4603068eddd8
diff --git a/notfair-cmo/src/components/browse-connectors-dialog.tsx b/notfair-cmo/src/components/browse-connectors-dialog.tsx
index a0bfcefc..3eee9b47 100644
--- a/notfair-cmo/src/components/browse-connectors-dialog.tsx
+++ b/notfair-cmo/src/components/browse-connectors-dialog.tsx
@@ -116,7 +116,15 @@ function ConnectorTile({
// Chain straight into OAuth so the user only clicks once. The
// upcoming full-page redirect is the visible feedback — we
// intentionally don't toast a separate "added" success.
- const connectResult = await startMcpConnect({ mcp_key: addResult.key });
+ //
+ // Pass `return_to` so the OAuth callback lands the user back on
+ // the connections page they started from. Without it the callback
+ // falls back to `/`, which bounces to the active project's home.
+ const return_to = window.location.pathname + window.location.search;
+ const connectResult = await startMcpConnect({
+ mcp_key: addResult.key,
+ return_to,
+ });
if (!connectResult.ok) {
toast.error(
`Added ${connector.display_name}, but couldn't start OAuth: ${connectResult.error}`,
diff --git a/notfair-cmo/src/components/mcp-card.test.tsx b/notfair-cmo/src/components/mcp-card.test.tsx
index c445346d..12513fd1 100644
--- a/notfair-cmo/src/components/mcp-card.test.tsx
+++ b/notfair-cmo/src/components/mcp-card.test.tsx
@@ -164,7 +164,10 @@ describe("McpCard", () => {
render(<McpCard spec={spec} status={{ state: "not_configured" }} />);
fireEvent.click(screen.getByRole("button", { name: /^connect$/i }));
await waitFor(() =>
- expect(startMcpConnect).toHaveBeenCalledWith({ mcp_key: spec.key }),
+ expect(startMcpConnect).toHaveBeenCalledWith({
+ mcp_key: spec.key,
+ return_to: "/",
+ }),
);
await waitFor(() =>
expect(loc.href).toBe("https://issuer.example/oauth?state=abc"),
diff --git a/notfair-cmo/src/components/mcp-card.tsx b/notfair-cmo/src/components/mcp-card.tsx
index ca8c4365..05df61cc 100644
--- a/notfair-cmo/src/components/mcp-card.tsx
+++ b/notfair-cmo/src/components/mcp-card.tsx
@@ -44,7 +44,13 @@ export function McpCard({ spec, status }: Props) {
async function onConnect() {
setBusy("connect");
try {
- const result = await startMcpConnect({ mcp_key: spec.key });
+ // Carry the current connections-page URL through OAuth so the
+ // callback lands the user back here. Without it, the callback
+ // falls through to `/`, which bounces to the active project's
+ // home — making it look like the connect flow "redirected to a
+ // different project" when really it just lost the return target.
+ const return_to = window.location.pathname + window.location.search;
+ const result = await startMcpConnect({ mcp_key: spec.key, return_to });
if (!result.ok) {
toast.error(result.error);
setBusy(null);