Skip to content

Commit a47063d

Browse files
authored
fix: tslint (#30)
1 parent 81bb59e commit a47063d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/jwt.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,18 +273,21 @@ async function parseHeader(ctx: RouterContext, type = TokenType.ACCESS) {
273273
const token = parts[1];
274274

275275
if (/^Bearer$/i.test(scheme)) {
276+
// @ts-ignore
276277
const obj = ctx.jwt.verifyToken(token);
277278
if (!get(obj, 'type') || get(obj, 'type') !== type) {
278279
ctx.throw(new AuthFailed({ msg: '请使用正确类型的令牌' }));
279280
}
280281
if (!get(obj, 'scope') || get(obj, 'scope') !== 'lin') {
281282
ctx.throw(new AuthFailed({ msg: '请使用正确作用域的令牌' }));
282283
}
284+
// @ts-ignore
283285
const user = await ctx.manager.userModel.findByPk(get(obj, 'identity'));
284286
if (!user) {
285287
ctx.throw(new NotFound({ msg: '用户不存在' }));
286288
}
287289
// 将user挂在ctx上
290+
// @ts-ignore
288291
ctx.currentUser = user;
289292
}
290293
} else {
@@ -306,6 +309,7 @@ async function loginRequired(ctx: RouterContext, next: () => Promise<any>) {
306309
await parseHeader(ctx);
307310
// 一定要await,否则这个守卫函数没有作用
308311
// 用户处于未激活状态
312+
// @ts-ignore
309313
const currentUser = ctx.currentUser;
310314
checkUserIsActive(currentUser);
311315
await next();
@@ -356,6 +360,7 @@ async function refreshTokenRequiredWithUnifyException(
356360
async function groupRequired(ctx: RouterContext, next: () => Promise<any>) {
357361
if (ctx.request.method !== 'OPTIONS') {
358362
await parseHeader(ctx);
363+
// @ts-ignore
359364
const currentUser = ctx.currentUser;
360365
// 用户处于未激活状态
361366
checkUserIsActive(currentUser);
@@ -369,10 +374,13 @@ async function groupRequired(ctx: RouterContext, next: () => Promise<any>) {
369374
msg: '您还不属于任何权限组,请联系超级管理员获得权限'
370375
});
371376
}
377+
// @ts-ignore
372378
if (ctx.matched) {
379+
// @ts-ignore
373380
const routeName = ctx._matchedRouteName || ctx.routerName;
374381
const endpoint = `${ctx.method} ${routeName}`;
375382
const { auth, module } = routeMetaInfo.get(endpoint);
383+
// @ts-ignore
376384
const item = await ctx.manager.authModel.findOne({
377385
where: { auth, module, group_id: groupId }
378386
});
@@ -397,6 +405,7 @@ async function groupRequired(ctx: RouterContext, next: () => Promise<any>) {
397405
async function adminRequired(ctx: RouterContext, next: () => Promise<any>) {
398406
if (ctx.request.method !== 'OPTIONS') {
399407
await parseHeader(ctx);
408+
// @ts-ignore
400409
const currentUser = ctx.currentUser;
401410
if (currentUser && currentUser.isAdmin) {
402411
await next();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lin-mizar",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "The core library of Lin CMS",
55
"main": "lin/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)