Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 1x 1x 1x 1x 1x 1x 1x 1x 1x | require('dotenv').config()
const fp = require('fastify-plugin')
module.exports = fp(async function (fastify, opts) {
fastify.register(require('@fastify/jwt'), {
secret: process.env.SECRET_KEY,
cookie: {
cookieName: 'token',
signed: true
}
})
fastify.decorate('authenticate', async function (request, reply) {
try {
await request.jwtVerify({ onlyCookie: true })
if (request.url === '/welcome' || request.url === '/login' || request.url === '/register') {
return reply.redirect(302, '/')
}
} catch (err) {
Iif (request.url === '/welcome' || request.url === '/login' || request.url === '/register') {
return err
}
return reply.redirect(302, '/welcome')
}
})
})
|