Skip to content

Commit 09a2f4c

Browse files
fix(proxy): matcher 排除 oauth/auth/analytics,修复登录 404
#330 i18n PR 让 next-intl middleware 接管全站 locale routing,但 matcher 只排除了 api/trpc/_next/_vercel/静态资源,没排除 next.config.mjs 的 rewrites 直通后端的路径。现象: - 用户访问 /oauth/render/github - next-intl middleware 308 redirect 到 /en/oauth/render/github (按 cookie / Accept-Language 推断 locale) - next.config rewrite source 是 /oauth/:path* 不带 locale,不匹配 - 落到 app/[locale]/oauth/... 但这个 page 不存在 → 404 - 登录炸 3 条 rewrite-to-backend 路径都要排: - /auth/:path* NextAuth-like (/auth/me, /auth/logout) - /oauth/:path* OAuth 跳转入口(登录关键) - /analytics/:path* 埋点 加进 matcher 排除组: /((?!api|trpc|auth|oauth|analytics|_next|_vercel|.*\..*).*)
1 parent 2425d9a commit 09a2f4c

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

proxy.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ export function proxy(req: NextRequest) {
8383
export const config = {
8484
// Match all pathnames except for
8585
// - api / trpc:API 路由不进 i18n(无 UI,纯 fetch)
86+
// - auth / oauth / analytics:next.config rewrites 直通后端的路径
87+
// (登录 / OAuth / 埋点)。被 next-intl 加了 locale 前缀后,
88+
// rewrite source(/oauth/:path*)不匹配带 locale 的版本(/en/oauth/...),
89+
// 落到 [locale]/oauth/... 404。所以必须排除掉,让请求直接走 rewrite。
8690
// - _next / _vercel:Next.js 内部
8791
// - .*\..*:任何带 . 的路径(静态资源 / sitemap.xml / robots.txt 等)
88-
matcher: "/((?!api|trpc|_next|_vercel|.*\\..*).*)",
92+
matcher: "/((?!api|trpc|auth|oauth|analytics|_next|_vercel|.*\\..*).*)",
8993
};

0 commit comments

Comments
 (0)