@@ -273,18 +273,21 @@ async function parseHeader(ctx: RouterContext, type = TokenType.ACCESS) {
273
273
const token = parts [ 1 ] ;
274
274
275
275
if ( / ^ B e a r e r $ / i. test ( scheme ) ) {
276
+ // @ts -ignore
276
277
const obj = ctx . jwt . verifyToken ( token ) ;
277
278
if ( ! get ( obj , 'type' ) || get ( obj , 'type' ) !== type ) {
278
279
ctx . throw ( new AuthFailed ( { msg : '请使用正确类型的令牌' } ) ) ;
279
280
}
280
281
if ( ! get ( obj , 'scope' ) || get ( obj , 'scope' ) !== 'lin' ) {
281
282
ctx . throw ( new AuthFailed ( { msg : '请使用正确作用域的令牌' } ) ) ;
282
283
}
284
+ // @ts -ignore
283
285
const user = await ctx . manager . userModel . findByPk ( get ( obj , 'identity' ) ) ;
284
286
if ( ! user ) {
285
287
ctx . throw ( new NotFound ( { msg : '用户不存在' } ) ) ;
286
288
}
287
289
// 将user挂在ctx上
290
+ // @ts -ignore
288
291
ctx . currentUser = user ;
289
292
}
290
293
} else {
@@ -306,6 +309,7 @@ async function loginRequired(ctx: RouterContext, next: () => Promise<any>) {
306
309
await parseHeader ( ctx ) ;
307
310
// 一定要await,否则这个守卫函数没有作用
308
311
// 用户处于未激活状态
312
+ // @ts -ignore
309
313
const currentUser = ctx . currentUser ;
310
314
checkUserIsActive ( currentUser ) ;
311
315
await next ( ) ;
@@ -356,6 +360,7 @@ async function refreshTokenRequiredWithUnifyException(
356
360
async function groupRequired ( ctx : RouterContext , next : ( ) => Promise < any > ) {
357
361
if ( ctx . request . method !== 'OPTIONS' ) {
358
362
await parseHeader ( ctx ) ;
363
+ // @ts -ignore
359
364
const currentUser = ctx . currentUser ;
360
365
// 用户处于未激活状态
361
366
checkUserIsActive ( currentUser ) ;
@@ -369,10 +374,13 @@ async function groupRequired(ctx: RouterContext, next: () => Promise<any>) {
369
374
msg : '您还不属于任何权限组,请联系超级管理员获得权限'
370
375
} ) ;
371
376
}
377
+ // @ts -ignore
372
378
if ( ctx . matched ) {
379
+ // @ts -ignore
373
380
const routeName = ctx . _matchedRouteName || ctx . routerName ;
374
381
const endpoint = `${ ctx . method } ${ routeName } ` ;
375
382
const { auth, module } = routeMetaInfo . get ( endpoint ) ;
383
+ // @ts -ignore
376
384
const item = await ctx . manager . authModel . findOne ( {
377
385
where : { auth, module, group_id : groupId }
378
386
} ) ;
@@ -397,6 +405,7 @@ async function groupRequired(ctx: RouterContext, next: () => Promise<any>) {
397
405
async function adminRequired ( ctx : RouterContext , next : ( ) => Promise < any > ) {
398
406
if ( ctx . request . method !== 'OPTIONS' ) {
399
407
await parseHeader ( ctx ) ;
408
+ // @ts -ignore
400
409
const currentUser = ctx . currentUser ;
401
410
if ( currentUser && currentUser . isAdmin ) {
402
411
await next ( ) ;
0 commit comments