fix: check specifically for session_token cookie, not all better-auth cookies

This commit is contained in:
2026-04-26 19:44:37 +08:00
parent 2cc2834e0f
commit 25aa52ada3
+4 -2
View File
@@ -12,12 +12,14 @@ export function proxy(req: NextRequest) {
const path = req.nextUrl.pathname
const isAuthRoute = authRoutes.some((route) => path.startsWith(route))
// Check for better-auth session cookie (default name: better-auth.session_token)
// Check specifically for the session token cookie
// (better-auth.session_token or __Secure-better-auth.session_token in HTTPS)
// Other better-auth cookies like last_used_login_method persist after logout
const hasSession = req.cookies
.getAll()
.some(
(cookie) =>
cookie.name.startsWith("better-auth.") &&
cookie.name.endsWith("better-auth.session_token") &&
cookie.value.length > 0,
)