From a9e9ddd04bae6dc240b584335531341f95a7c5e6 Mon Sep 17 00:00:00 2001 From: luorijun Date: Wed, 1 Apr 2026 13:16:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=89=B4=E6=9D=83=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=90=8E=E8=B7=B3=E8=BD=AC=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/actions/auth.ts | 12 ++---------- src/proxy.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/actions/auth.ts b/src/actions/auth.ts index 0dabb64..9072baa 100644 --- a/src/actions/auth.ts +++ b/src/actions/auth.ts @@ -61,16 +61,8 @@ export async function logout() { } // 删除 cookies - cookieStore.set("admin/auth_token", "", { - httpOnly: true, - sameSite: "strict", - maxAge: -1, - }) - cookieStore.set("admin/auth_refresh", "", { - httpOnly: true, - sameSite: "strict", - maxAge: -1, - }) + cookieStore.delete("admin/auth_token") + cookieStore.delete("admin/auth_refresh") return { success: true, diff --git a/src/proxy.ts b/src/proxy.ts index db17533..4469cbe 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -33,15 +33,15 @@ export async function proxy(request: NextRequest) { } // 验证访问令牌 - const hasToken = !!request.cookies.get("admin/auth_token") + const hasToken = request.cookies.has("admin/auth_token") // const isToAdmin = request.nextUrl.pathname.startsWith("/admin") - const protectedPaths = ["/", "/admin"] - const isProtectedPath = protectedPaths.some( - path => - request.nextUrl.pathname === path || - request.nextUrl.pathname.startsWith(`${path}/`), + const ignoredPaths = ["/login"] + const ignored = ignoredPaths.some(path => + request.nextUrl.pathname.startsWith(path), ) - if (!hasToken && isProtectedPath) { + + console.log("hasToken", hasToken, "ignored", ignored) + if (!hasToken && !ignored) { return NextResponse.redirect( `${request.nextUrl.origin}/login?redirect=${request.nextUrl.pathname}`, )