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 { App, Config, Inject, Middleware } from '@midwayjs/decorator';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import { CoolCommException, RESCODE } from '@cool-midway/core';
|
import { RESCODE } from '@cool-midway/core';
|
||||||
import * as jwt from 'jsonwebtoken';
|
import * as jwt from 'jsonwebtoken';
|
||||||
import { NextFunction, Context } from '@midwayjs/koa';
|
import { NextFunction, Context } from '@midwayjs/koa';
|
||||||
import { IMiddleware, IMidwayApplication } from '@midwayjs/core';
|
import { IMiddleware, IMidwayApplication } from '@midwayjs/core';
|
||||||
@ -38,10 +38,15 @@ export class BaseAuthorityMiddleware
|
|||||||
if (_.startsWith(url, adminUrl)) {
|
if (_.startsWith(url, adminUrl)) {
|
||||||
try {
|
try {
|
||||||
ctx.admin = jwt.verify(token, this.jwtConfig.jwt.secret);
|
ctx.admin = jwt.verify(token, this.jwtConfig.jwt.secret);
|
||||||
} catch (err) {
|
if (ctx.admin.isRefresh) {
|
||||||
throw new CoolCommException('登录失效~');
|
ctx.status = 401;
|
||||||
}
|
ctx.body = {
|
||||||
if (ctx.admin.isRefresh) throw new CoolCommException('登录失效~');
|
code: RESCODE.COMMFAIL,
|
||||||
|
message: '登录失效~',
|
||||||
|
};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (error) {}
|
||||||
// 不需要登录 无需权限校验
|
// 不需要登录 无需权限校验
|
||||||
if (
|
if (
|
||||||
new RegExp(`^${adminUrl}?.*/open/`).test(url) ||
|
new RegExp(`^${adminUrl}?.*/open/`).test(url) ||
|
||||||
|
Loading…
Reference in New Issue
Block a user