initial production release 🎉

This commit is contained in:
Andras
2021-03-24 22:11:14 +01:00
commit dbe82b3e7c
101 changed files with 12479 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
const fp = require('fastify-plugin')
const User = require('../models/User')
module.exports = fp(async function (fastify, options, next) {
fastify.register(require('fastify-jwt'), {
secret: fastify.config.JWT_SIGN_KEY
})
fastify.addHook('onRequest', async (request, reply) => {
try {
const { jti } = await request.jwtVerify()
const found = await User.findOne({ uid: jti })
if (found) {
return true
} else {
reply.code(401).send('Unauthorized')
}
} catch (err) {
reply.code(401).send('Unauthorized')
}
})
next()
})