web-server 注册、登录、获取服务器列表;game-server token 校验
This commit is contained in:
19
web-server/app/middleware/tokenParser.ts
Normal file
19
web-server/app/middleware/tokenParser.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user