forked from admin/hair-keeper
基于Redis失效标记,实现用户权限变更后强制重新登录
This commit is contained in:
@@ -9,8 +9,8 @@ export default withAuth(
|
||||
const token = req.nextauth.token
|
||||
const pathname = req.nextUrl.pathname
|
||||
|
||||
// 如果用户已登录且访问登录页面,重定向到首页
|
||||
if (pathname === "/login" && token) {
|
||||
// 如果用户已登录且访问登录页面,重定向到首页(会话失效的用户除外,需留在登录页)
|
||||
if (pathname === "/login" && token && !token.sessionInvalid) {
|
||||
return NextResponse.redirect(new URL("/", req.url))
|
||||
}
|
||||
|
||||
@@ -49,7 +49,12 @@ export default withAuth(
|
||||
if (req.nextUrl.pathname === "/login") {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
// 会话已被标记失效,强制重新登录
|
||||
if (token?.sessionInvalid) {
|
||||
return false
|
||||
}
|
||||
|
||||
// 其他路由需要有效的 token
|
||||
return !!token
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user