修改代码格式;
数据库查询加 lean 判断; 其它内容微调。
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
import { STATUS_TOKEN_ERR, STATUS_WRONG_PARMS } from './../../../shared/statusCode';
|
||||
import { UserModel } from './../db/User';
|
||||
import { Context } from 'egg';
|
||||
|
||||
module.exports = () => {
|
||||
return async function tokenParser(ctx: Context, next) {
|
||||
if (!ctx.request.body || !ctx.request.body.token) {
|
||||
ctx.body = ctx.service.utils.exceptionResult(STATUS_WRONG_PARMS);
|
||||
return;
|
||||
}
|
||||
const user = await UserModel.findUserByToken(ctx.request.body.token);
|
||||
if (!user) {
|
||||
console.log('token invalid');
|
||||
ctx.body = ctx.service.utils.exceptionResult(STATUS_TOKEN_ERR);
|
||||
return;
|
||||
}
|
||||
await next();
|
||||
return async function tokenParser(ctx, next) {
|
||||
if (!ctx.request.body || !ctx.request.body.token) {
|
||||
console.error('token not found');
|
||||
ctx.body = ctx.service.utils.exceptionResult(STATUS_WRONG_PARMS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
const user = await UserModel.findUserByToken(ctx.request.body.token);
|
||||
if (!user) {
|
||||
console.error('token invalid');
|
||||
ctx.body = ctx.service.utils.exceptionResult(STATUS_TOKEN_ERR);
|
||||
return;
|
||||
}
|
||||
await next();
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user