Context
src/server.ts:
server.decorate("authenticate", async function (request: any, reply: any) {
try {
await request.jwtVerify();
} catch (err) {
reply.send(err);
}
});
Two things worth fixing here. The any parameters mean route handlers get no type safety on request.user, and because the decorator isn't declared on FastifyInstance, every call site referencing fastify.authenticate is either untyped or cast.
Separately, the catch calls reply.send(err) without an explicit status. It happens to produce a 401 because @fastify/jwt errors carry a statusCode, but that's implicit and easy to break.
What to do
- Use
FastifyRequest / FastifyReply types
- Add a module augmentation declaring
authenticate on FastifyInstance, and the JWT payload shape (sub, wallet, slug — see verifyChallenge in src/modules/auth/auth.service.ts) on @fastify/jwt
- Set the status code explicitly before sending
Acceptance criteria
Context
src/server.ts:Two things worth fixing here. The
anyparameters mean route handlers get no type safety onrequest.user, and because the decorator isn't declared onFastifyInstance, every call site referencingfastify.authenticateis either untyped or cast.Separately, the catch calls
reply.send(err)without an explicit status. It happens to produce a 401 because@fastify/jwterrors carry astatusCode, but that's implicit and easy to break.What to do
FastifyRequest/FastifyReplytypesauthenticateonFastifyInstance, and the JWT payload shape (sub,wallet,slug— seeverifyChallengeinsrc/modules/auth/auth.service.ts) on@fastify/jwtAcceptance criteria
anyin the decoratorrequest.useris typed at call sitesnpm run typecheckpasses