mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2024-11-01 22:20:30 +08:00
完善权限校验
This commit is contained in:
parent
56c288324b
commit
92e4ce85df
@ -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) ||
|
||||
|
Loading…
Reference in New Issue
Block a user