修改接口的验证方式

This commit is contained in:
zhl 2021-01-13 15:44:22 +08:00
parent 2099384e46
commit be30ef7e3e

View File

@ -30,29 +30,30 @@ const apiAuthPlugin: FastifyPluginAsync = async function(
try { try {
if (request.roles.indexOf('svr') >= 0) { if (request.roles.indexOf('svr') >= 0) {
// TODO: check svr // TODO: check svr
return; } else {
// @ts-ignore
let { accountid, sessionid } = request.params;
//TODO: 增加sessionid的校验
// if (!accountid || !sessionid) {
// return reply.send({code: 11, msg: 'need accountid and sessionid'});
// }
if (!accountid) {
return reply.send({code: 2, msg: 'need accountid and sessionid'});
}
// const data = this.jwt.verify(request.token);
// if (!data || !data.id) {
// return reply.send({code: 10, msg: 'need login'});
// }
let account = await User.findById(accountid);
if (!account) {
return reply.send({code: 5, msg: 'account not found'});
}
if (account.locked) {
return reply.send({code: 4, msg: 'account locked'});
}
request.user = account;
} }
// @ts-ignore
let { accountid, sessionid } = request.params;
//TODO: 增加sessionid的校验
// if (!accountid || !sessionid) {
// return reply.send({code: 11, msg: 'need accountid and sessionid'});
// }
if (!accountid) {
return reply.send({code: 2, msg: 'need accountid and sessionid'});
}
// const data = this.jwt.verify(request.token);
// if (!data || !data.id) {
// return reply.send({code: 10, msg: 'need login'});
// }
let account = await User.findById(accountid);
if (!account) {
return reply.send({code: 5, msg: 'account not found'});
}
if (account.locked) {
return reply.send({code: 4, msg: 'account locked'});
}
request.user = account;
} catch (err) { } catch (err) {
return reply.send({code: 401, msg: 'need auth'}) return reply.send({code: 401, msg: 'need auth'})
} }