Answers for "fastify-trusted"

0

fastify-trusted

const fastify = require('fastify')()

fastify.register(require('fastify-jwt'), {
  secret: 'foobar',
  trusted: validateToken
})

fastify.addHook('onRequest', (request) => request.jwtVerify())

fastify.get('/', (request, reply) => {
  reply.send({ code: 'OK', message: 'it works!' })
})

fastify.listen(3000, (err) => {
  if (err) {
    throw err
  }
})

// ideally this function would do a query against some sort of storage to determine its outcome
async function validateToken(request, decodedToken) {
  const denylist = ['token1', 'token2']

  return !denylist.includes(decodedToken.jti)
}
Posted by: Guest on May-11-2021

Code answers related to "fastify-trusted"

Code answers related to "Javascript"

Browse Popular Code Answers by Language