修复鉴权失败后跳转的问题
This commit is contained in:
@@ -61,16 +61,8 @@ export async function logout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 删除 cookies
|
// 删除 cookies
|
||||||
cookieStore.set("admin/auth_token", "", {
|
cookieStore.delete("admin/auth_token")
|
||||||
httpOnly: true,
|
cookieStore.delete("admin/auth_refresh")
|
||||||
sameSite: "strict",
|
|
||||||
maxAge: -1,
|
|
||||||
})
|
|
||||||
cookieStore.set("admin/auth_refresh", "", {
|
|
||||||
httpOnly: true,
|
|
||||||
sameSite: "strict",
|
|
||||||
maxAge: -1,
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
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 isToAdmin = request.nextUrl.pathname.startsWith("/admin")
|
||||||
const protectedPaths = ["/", "/admin"]
|
const ignoredPaths = ["/login"]
|
||||||
const isProtectedPath = protectedPaths.some(
|
const ignored = ignoredPaths.some(path =>
|
||||||
path =>
|
request.nextUrl.pathname.startsWith(path),
|
||||||
request.nextUrl.pathname === path ||
|
|
||||||
request.nextUrl.pathname.startsWith(`${path}/`),
|
|
||||||
)
|
)
|
||||||
if (!hasToken && isProtectedPath) {
|
|
||||||
|
console.log("hasToken", hasToken, "ignored", ignored)
|
||||||
|
if (!hasToken && !ignored) {
|
||||||
return NextResponse.redirect(
|
return NextResponse.redirect(
|
||||||
`${request.nextUrl.origin}/login?redirect=${request.nextUrl.pathname}`,
|
`${request.nextUrl.origin}/login?redirect=${request.nextUrl.pathname}`,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user