File size: 469 Bytes
6dd9bad | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import { FastifyRequest, FastifyReply } from 'fastify';
/**
* Middleware to verify JWT token.
* Throws an error if the token is invalid or missing.
*/
export const verifyJwt = async (request: FastifyRequest, reply: FastifyReply) => {
try {
await request.jwtVerify();
} catch (err) {
reply.code(401).send({ error: 'Unauthorized', message: 'Invalid or missing token' });
throw err; // Stop further execution in the hook chain
}
};
|