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
ad1bfdad63
commit
dca122691e
@ -6,6 +6,7 @@ import {
|
||||
CoolUrlTag,
|
||||
CoolTag,
|
||||
TagTypes,
|
||||
RESCODE,
|
||||
} from '@cool-midway/core';
|
||||
import { LoginDTO } from '../../dto/login';
|
||||
import { BaseSysLoginService } from '../../service/sys/login';
|
||||
@ -84,6 +85,15 @@ export class BaseOpenController extends BaseController {
|
||||
@CoolTag(TagTypes.IGNORE_TOKEN)
|
||||
@Get('/refreshToken', { summary: '刷新token' })
|
||||
async refreshToken(@Query('refreshToken') refreshToken: string) {
|
||||
return this.ok(await this.baseSysLoginService.refreshToken(refreshToken));
|
||||
try {
|
||||
const token = await this.baseSysLoginService.refreshToken(refreshToken);
|
||||
return this.ok(token);
|
||||
} catch (e) {
|
||||
this.ctx.status = 401;
|
||||
this.ctx.body = {
|
||||
code: RESCODE.COMMFAIL,
|
||||
message: '登录失效~',
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ export class BaseAuthorityMiddleware
|
||||
return async (ctx: Context, next: NextFunction) => {
|
||||
let statusCode = 200;
|
||||
let { url } = ctx;
|
||||
url = url.replace(this.prefix, '');
|
||||
url = url.replace(this.prefix, '').split('?')[0];
|
||||
const token = ctx.get('Authorization');
|
||||
const adminUrl = '/admin/';
|
||||
// 路由地址为 admin前缀的 需要权限校验
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Inject, Provide, Config } from '@midwayjs/decorator';
|
||||
import { BaseService, CoolCommException, RESCODE } from '@cool-midway/core';
|
||||
import { BaseService, CoolCommException } from '@cool-midway/core';
|
||||
import { LoginDTO } from '../../dto/login';
|
||||
import * as svgCaptcha from 'svg-captcha';
|
||||
import { v1 as uuid } from 'uuid';
|
||||
@ -217,7 +217,6 @@ export class BaseSysLoginService extends BaseService {
|
||||
* @param token
|
||||
*/
|
||||
async refreshToken(token: string) {
|
||||
try {
|
||||
const decoded = jwt.verify(token, this.coolConfig.jwt.secret);
|
||||
if (decoded && decoded['isRefresh']) {
|
||||
delete decoded['exp'];
|
||||
@ -247,13 +246,5 @@ export class BaseSysLoginService extends BaseService {
|
||||
);
|
||||
return result;
|
||||
}
|
||||
} catch (err) {
|
||||
this.ctx.status = 401;
|
||||
this.ctx.body = {
|
||||
code: RESCODE.COMMFAIL,
|
||||
message: '登录失效~',
|
||||
};
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user