Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions apps/backend/src/routes/nfc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';

Check failure on line 1 in apps/backend/src/routes/nfc.ts

View workflow job for this annotation

GitHub Actions / backend-ci

There should be at least one empty line between import groups
import { z } from 'zod';

Check failure on line 2 in apps/backend/src/routes/nfc.ts

View workflow job for this annotation

GitHub Actions / backend-ci

`zod` import should occur before type import of `fastify`

type NfcPayloadResponse = {
Expand All @@ -10,20 +10,24 @@
card: z.string().uuid('Invalid card ID format').optional(),
});

interface JwtPayload {
id: string;
}

export async function nfcRoutes(app: FastifyInstance) {

Check warning on line 17 in apps/backend/src/routes/nfc.ts

View workflow job for this annotation

GitHub Actions / backend-ci

Missing return type on function
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 {
await request.jwtVerify();
} catch (e) {

Check failure on line 30 in apps/backend/src/routes/nfc.ts

View workflow job for this annotation

GitHub Actions / backend-ci

'e' is defined but never used. Allowed unused caught errors must match /^_/u
reply.status(401).send({ error: 'Unauthorized' });
}
});
Expand All @@ -36,7 +40,7 @@
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);
Expand Down
Loading