mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-13 18:02:59 -05:00
* chore: compile TS into /dist Having the output co-located with the source meant that the js would be imported by default. Given that we don't recompile on source changes, this means the server got 'stuck' at the point of compilation and would only register changes on build. Also, compiling to a dist directory should make it easier to build when we want to deploy. That said, the motivation is mostly DX. * fix: put schema.prisma in the default location
26 lines
614 B
TypeScript
26 lines
614 B
TypeScript
import { FastifyPluginCallback, onRequestHookHandler } from 'fastify';
|
|
import fp from 'fastify-plugin';
|
|
|
|
const sessionAuth: FastifyPluginCallback = (fastify, _opts, done) => {
|
|
const authenticateSession: onRequestHookHandler = (req, res, done) => {
|
|
if (!req.session.user) {
|
|
res.statusCode = 401;
|
|
void res.send({ msg: 'Unauthorized' });
|
|
} else {
|
|
done();
|
|
}
|
|
};
|
|
|
|
fastify.decorate('authenticateSession', authenticateSession);
|
|
|
|
done();
|
|
};
|
|
|
|
declare module 'fastify' {
|
|
interface FastifyInstance {
|
|
authenticateSession: onRequestHookHandler;
|
|
}
|
|
}
|
|
|
|
export default fp(sessionAuth);
|