From e0ab981113b08103dbf846f1ad5cd8bb53c625b4 Mon Sep 17 00:00:00 2001 From: openclawloulou-ai Date: Sat, 13 Jun 2026 12:00:03 +0000 Subject: [PATCH] fix: Improve Type Safety in nfc.ts and Remove Remaining Usage Closes #551 Automated contribution following repo conventions. --- apps/backend/src/routes/nfc.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/backend/src/routes/nfc.ts b/apps/backend/src/routes/nfc.ts index 5cf13f0c..c46ed932 100644 --- a/apps/backend/src/routes/nfc.ts +++ b/apps/backend/src/routes/nfc.ts @@ -10,15 +10,19 @@ const nfcQuerySchema = z.object({ card: z.string().uuid('Invalid card ID format').optional(), }); +interface JwtPayload { + id: string; +} + export async function nfcRoutes(app: FastifyInstance) { app.addHook('preHandler', async (request, reply) => { - const server = request.server as any; + const server = request.server as FastifyInstance; if (typeof server?.authenticate === 'function') { await server.authenticate(request, reply); return; } - if (typeof (app as any).authenticate === 'function') { - await (app as any).authenticate(request, reply); + if (typeof app.authenticate === 'function') { + await app.authenticate(request, reply); return; } try { @@ -36,7 +40,7 @@ export async function nfcRoutes(app: FastifyInstance) { request: FastifyRequest<{ Querystring: { card?: string } }>, reply: FastifyReply ) => { - const userId = (request.user as any).id; + const userId = (request.user as JwtPayload).id; // Validate query params with Zod const parseResult = nfcQuerySchema.safeParse(request.query);