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 } };