change response data of unauth

This commit is contained in:
zhl 2023-05-31 15:25:09 +08:00
parent 0915d5f153
commit 23bc433368

View File

@ -27,12 +27,12 @@ const apiAuthPlugin: FastifyPluginAsync<ApiAuthOptions> = async function (fastif
if (!request.roles || request.roles.indexOf('anon') == -1) {
try {
if (!request.token) {
return reply.send({ code: 11, msg: 'need login' })
return reply.send({ errcode: 11, errmsg: 'need login' })
}
//@ts-ignore
const data = this.jwt.verify(request.token)
if (!data || !data.id) {
return reply.send({ code: 10, msg: 'need login' })
return reply.send({ errcode: 10, errmsg: 'need login' })
}
// let account = await Account.findById(data.id)
// if (!account) {
@ -40,7 +40,7 @@ const apiAuthPlugin: FastifyPluginAsync<ApiAuthOptions> = async function (fastif
// }
// request.user = account
} catch (err) {
return reply.send({ code: 401, msg: 'need auth' })
return reply.send({ errcode: 401, errmsg: 'need auth' })
}
}
})