From 33335c952382d367afcc51e7f835f280cd57aab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=B9=8F?= Date: Thu, 14 Jul 2022 14:08:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dsso=E5=8D=95=E7=82=B9?= =?UTF-8?q?=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/base/middleware/authority.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/modules/base/middleware/authority.ts b/src/modules/base/middleware/authority.ts index ce8f844..a0ef2cf 100644 --- a/src/modules/base/middleware/authority.ts +++ b/src/modules/base/middleware/authority.ts @@ -43,10 +43,22 @@ export class BaseAuthorityMiddleware return; } if (ctx.admin) { + const rToken = await this.cacheManager.get( + `admin:token:${ctx.admin.userId}` + ); // 超管拥有所有权限 if (ctx.admin.username == 'admin' && !ctx.admin.isRefresh) { - await next(); - return; + if (rToken !== token && this.jwtConfig.jwt.sso) { + ctx.status = 401; + ctx.body = { + code: RESCODE.COMMFAIL, + message: '登录失效~', + }; + return; + } else { + await next(); + return; + } } // 要登录每个人都有权限的接口 if (new RegExp(`^${adminUrl}?.*/comm/`).test(url)) { @@ -74,9 +86,7 @@ export class BaseAuthorityMiddleware }; return; } - const rToken = await this.cacheManager.get( - `admin:token:${ctx.admin.userId}` - ); + if (!rToken) { ctx.status = 401; ctx.body = { @@ -85,7 +95,7 @@ export class BaseAuthorityMiddleware }; return; } - if (rToken !== token && this.jwtConfig.sso) { + if (rToken !== token && this.jwtConfig.jwt.sso) { statusCode = 401; } else { let perms: string[] = await this.cacheManager.get(