优化权限校验

This commit is contained in:
cool 2023-11-22 11:18:58 +08:00
parent dca122691e
commit 85888bc420

View File

@ -21,6 +21,9 @@ export class UserMiddleware implements IMiddleware<Context, NextFunction> {
ignoreUrls: string[] = []; ignoreUrls: string[] = [];
@Config('koa.globalPrefix')
prefix;
@Init() @Init()
async init() { async init() {
this.ignoreUrls = this.coolUrlTagData.byKey(TagTypes.IGNORE_TOKEN, 'app'); this.ignoreUrls = this.coolUrlTagData.byKey(TagTypes.IGNORE_TOKEN, 'app');
@ -29,7 +32,7 @@ export class UserMiddleware implements IMiddleware<Context, NextFunction> {
resolve() { resolve() {
return async (ctx: Context, next: NextFunction) => { return async (ctx: Context, next: NextFunction) => {
let { url } = ctx; let { url } = ctx;
url = url.split('?')[0]; url = url.replace(this.prefix, '').split('?')[0];
if (_.startsWith(url, '/app/')) { if (_.startsWith(url, '/app/')) {
const token = ctx.get('Authorization'); const token = ctx.get('Authorization');
try { try {