Fixed auth error crashing the entire server thanks to fastify handling stuff not the same way that they do in the docs.....
closes #1
This commit is contained in:
parent
4ffc06db7b
commit
dbb0d177b8
|
@ -45,25 +45,31 @@ fastify.decorate('verifyJWT', function async(request, reply, done) {
|
|||
|
||||
fastify.jwt.verify(token, async (err, decoded) => {
|
||||
if (err) {
|
||||
fastify.log.error(err)
|
||||
done(new Error("JWT Validation failed"))
|
||||
fastify.log.error("JWT validation failed:")
|
||||
done(new Error("JWT Validation failed"));
|
||||
}
|
||||
fastify.log.info(`Token verified. User is ${decoded.payload.user}`);
|
||||
request.user = decoded.payload.user;
|
||||
else {
|
||||
if (!decoded.payload) {
|
||||
done(new Error("JWT is empty"));
|
||||
}
|
||||
fastify.log.info(`Token verified. User is ${decoded.payload.user}`);
|
||||
|
||||
const jwtcount = (await knex.select('jwtcount')
|
||||
.from('users')
|
||||
.where('username', '=', decoded.payload.user)
|
||||
.limit(1))[0].jwtcount;
|
||||
const jwtcount = (await knex.select('jwtcount')
|
||||
.from('users')
|
||||
.where('username', '=', decoded.payload.user)
|
||||
.limit(1))[0].jwtcount;
|
||||
|
||||
if (decoded.payload.jwtcount < jwtcount) {
|
||||
fastify.log.error("Auth ended at jwtcount")
|
||||
done(new Error("JWT in no longer valid"))
|
||||
if (decoded.payload.jwtcount < jwtcount) {
|
||||
fastify.log.error("Auth ended at jwtcount")
|
||||
done(new Error("JWT in no longer valid"))
|
||||
}
|
||||
else {
|
||||
fastify.log.info(`JWT count verified`);
|
||||
request.user = decoded.payload.user;
|
||||
done()
|
||||
}
|
||||
}
|
||||
fastify.log.info(`JWT count verified`);
|
||||
done()
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
//Automagic Amazn redirects on /a/
|
||||
|
|
Loading…
Reference in New Issue