From 404f27c3e1efd08d388395f45c33db70a62697e2 Mon Sep 17 00:00:00 2001 From: YJack0000 Date: Fri, 28 Aug 2026 20:34:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[fix]=20=E5=B8=B3=E5=AF=86=E7=99=BB?= =?UTF-8?q?=E5=85=A5=E5=9C=A8=20MCP=20OAuth=20=E6=B5=81=E7=A8=8B=E4=B8=8B?= =?UTF-8?q?=E5=8D=A1=E5=9C=A8=20Signing=20in=EF=BC=9A=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E6=95=B4=E9=A0=81=E5=B0=8E=E9=A0=81=E9=81=BF=E9=96=8B=20callba?= =?UTF-8?q?ckURL=20=E7=9A=84=E8=B7=A8=E7=B6=B2=E5=9F=9F=20fetch=20CORS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/login/page.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index f7f4470..1ed1a4b 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -101,15 +101,24 @@ function SignInMethods() { const email = typeof emailEntry === "string" ? emailEntry.trim() : ""; const password = typeof passwordEntry === "string" ? passwordEntry : ""; setPending(true); - const { error } = await signIn.email({ email, password, callbackURL: redirectTo }); + // ⚠️ 不能傳 callbackURL。better-auth 的 email 登入是走 fetch,帶 callbackURL + // 時伺服器會回 302,fetch 自動跟著 redirect 一路走;當 callbackURL 是 MCP 的 + // /api/auth/mcp/authorize(ChatGPT / Claude / Codex 的授權入口)時,它下一跳 + // 會 302 到 claude.ai/api/mcp/auth_callback(跨網域),fetch 撞 CORS 直接 + // Failed to fetch,按鈕永遠卡在 submitting、OAuth 斷掉。Google / SSO 沒這問題 + // 是因為它們走整頁跳轉。所以這裡只用 email 登入「建立 session」,成功後由我們 + // 自己做整頁導頁——top-level navigation 跟著 302 到 claude.ai 不受 CORS 限制。 + const { error } = await signIn.email({ email, password }); if (error) { setPending(false); // 401 一律講「email 或密碼不正確」,不區分哪一個錯 —— 分開講就成了帳號探測。 toast.error( error.status === 401 ? t("toast.badCredentials") : error.message || t("toast.failed"), ); + return; } - // 成功時 client 依 callbackURL 自行導頁。 + // session 已建立,整頁導去 redirectTo(可能是 MCP authorize,會再 302 去 claude.ai)。 + window.location.href = redirectTo; } return ( From f42332aa12801f8960e97cfe91b6b7466b2fd605 Mon Sep 17 00:00:00 2001 From: YJack0000 Date: Fri, 28 Aug 2026 20:38:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[fix]=20Sonar=EF=BC=9A=E6=94=B9=E7=94=A8=20?= =?UTF-8?q?globalThis.location=20=E5=8F=96=E4=BB=A3=20window.location?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/login/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index 1ed1a4b..3a28cfc 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -118,7 +118,7 @@ function SignInMethods() { return; } // session 已建立,整頁導去 redirectTo(可能是 MCP authorize,會再 302 去 claude.ai)。 - window.location.href = redirectTo; + globalThis.location.href = redirectTo; } return (