修复鉴权失败后跳转的问题
This commit is contained in:
@@ -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,
|
||||
|
||||
14
src/proxy.ts
14
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}`,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user