From 92e4ce85dfa55d6dd776515ec680f2d312f52a5e Mon Sep 17 00:00:00 2001 From: COOL Date: Sun, 16 Apr 2023 11:08:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=9D=83=E9=99=90=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/base/middleware/authority.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/modules/base/middleware/authority.ts b/src/modules/base/middleware/authority.ts index a3f673c..aecd0f7 100644 --- a/src/modules/base/middleware/authority.ts +++ b/src/modules/base/middleware/authority.ts @@ -1,6 +1,6 @@ import { App, Config, Inject, Middleware } from '@midwayjs/decorator'; import * as _ from 'lodash'; -import { CoolCommException, RESCODE } from '@cool-midway/core'; +import { RESCODE } from '@cool-midway/core'; import * as jwt from 'jsonwebtoken'; import { NextFunction, Context } from '@midwayjs/koa'; import { IMiddleware, IMidwayApplication } from '@midwayjs/core'; @@ -38,10 +38,15 @@ export class BaseAuthorityMiddleware if (_.startsWith(url, adminUrl)) { try { ctx.admin = jwt.verify(token, this.jwtConfig.jwt.secret); - } catch (err) { - throw new CoolCommException('登录失效~'); - } - if (ctx.admin.isRefresh) throw new CoolCommException('登录失效~'); + if (ctx.admin.isRefresh) { + ctx.status = 401; + ctx.body = { + code: RESCODE.COMMFAIL, + message: '登录失效~', + }; + return; + } + } catch (error) {} // 不需要登录 无需权限校验 if ( new RegExp(`^${adminUrl}?.*/open/`).test(url) ||