修复sso单点登录

This commit is contained in:
小鹏 2022-07-14 14:08:39 +08:00
parent 2a1028211e
commit 33335c9523

View File

@ -43,10 +43,22 @@ export class BaseAuthorityMiddleware
return; return;
} }
if (ctx.admin) { if (ctx.admin) {
const rToken = await this.cacheManager.get(
`admin:token:${ctx.admin.userId}`
);
// 超管拥有所有权限 // 超管拥有所有权限
if (ctx.admin.username == 'admin' && !ctx.admin.isRefresh) { if (ctx.admin.username == 'admin' && !ctx.admin.isRefresh) {
await next(); if (rToken !== token && this.jwtConfig.jwt.sso) {
return; ctx.status = 401;
ctx.body = {
code: RESCODE.COMMFAIL,
message: '登录失效~',
};
return;
} else {
await next();
return;
}
} }
// 要登录每个人都有权限的接口 // 要登录每个人都有权限的接口
if (new RegExp(`^${adminUrl}?.*/comm/`).test(url)) { if (new RegExp(`^${adminUrl}?.*/comm/`).test(url)) {
@ -74,9 +86,7 @@ export class BaseAuthorityMiddleware
}; };
return; return;
} }
const rToken = await this.cacheManager.get(
`admin:token:${ctx.admin.userId}`
);
if (!rToken) { if (!rToken) {
ctx.status = 401; ctx.status = 401;
ctx.body = { ctx.body = {
@ -85,7 +95,7 @@ export class BaseAuthorityMiddleware
}; };
return; return;
} }
if (rToken !== token && this.jwtConfig.sso) { if (rToken !== token && this.jwtConfig.jwt.sso) {
statusCode = 401; statusCode = 401;
} else { } else {
let perms: string[] = await this.cacheManager.get( let perms: string[] = await this.cacheManager.get(