From 7ad3539e76ec1d930fbd391645ecf85075d6d73c Mon Sep 17 00:00:00 2001 From: Brandon Lu <96360357+Lanznx@users.noreply.github.com> Date: Mon, 28 Sep 2026 20:21:08 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E8=88=8A=E7=B6=B2=E5=9D=80=20/settings?= =?UTF-8?q?=20=E7=AD=89=E8=BD=89=E5=9D=80=E5=88=B0=E5=AD=97=E9=9D=A2?= =?UTF-8?q?=E4=B8=8A=E7=9A=84=20/dashboard/settings/:path*=EF=BC=8C?= =?UTF-8?q?=E5=B0=8E=E8=87=B4=E7=99=BB=E5=85=A5=20INVALID=5FCALLBACK=5FURL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OpenNext 的 redirect matcher 只在 source 抓到參數時才會代換 destination。 `/:segment/:path*` 對沒有子路徑的網址抓到零段,destination 原字照回; 沒登入時這串被帶進 /login 的 callbackURL,better-auth 驗不過。 拆成 `/segment` 與 `/segment/:path+` 兩條。 Co-Authored-By: Claude Opus 5.5 --- next.config.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/next.config.ts b/next.config.ts index 7339d47..ad71ca5 100644 --- a/next.config.ts +++ b/next.config.ts @@ -162,11 +162,23 @@ const nextConfig: NextConfig = { }, }, async redirects() { - return MOVED_TO_DASHBOARD.map((segment) => ({ - source: `/${segment}/:path*`, - destination: `/dashboard/${segment}/:path*`, - permanent: true, - })); + // 拆成兩條,不能只寫一條 `/:segment/:path*`:OpenNext 的 redirect matcher + // 只有在 source 真的抓到參數時才會把 destination 丟進 compile() 代換, + // `/settings` 這種沒有子路徑的網址 `:path*` 抓到零段 → 沒有參數 → destination + // 原字照回,使用者被導去字面上的 `/dashboard/settings/:path*`。沒登入時這串 + // 又被帶進 /login 的 callbackURL,better-auth 驗不過就回 INVALID_CALLBACK_URL。 + return MOVED_TO_DASHBOARD.flatMap((segment) => [ + { + source: `/${segment}`, + destination: `/dashboard/${segment}`, + permanent: true, + }, + { + source: `/${segment}/:path+`, + destination: `/dashboard/${segment}/:path+`, + permanent: true, + }, + ]); }, async headers() { return [