edtech / apps /api /src /middleware /verifyJwt.ts
CognxSafeTrack
feat: backlog P0→P3 — toast system, payments, tenant isolation, feedback handler, i18n parity
6dd9bad
raw
history blame
469 Bytes
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
}
};