From 5cbbbe0236d578ae424740d5de5ad31a0d5073de Mon Sep 17 00:00:00 2001 From: ramnnnn2006 Date: Fri, 12 Jun 2026 19:31:28 +0530 Subject: [PATCH 1/3] refactor(backend): type authenticate decorator and jwt user payload --- apps/backend/src/types/fastify.d.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/apps/backend/src/types/fastify.d.ts b/apps/backend/src/types/fastify.d.ts index 8e7aee95..f6053ec4 100644 --- a/apps/backend/src/types/fastify.d.ts +++ b/apps/backend/src/types/fastify.d.ts @@ -1,8 +1,25 @@ import '@fastify/cookie'; -import { FastifyRequest } from 'fastify'; +import '@fastify/jwt'; +import { FastifyRequest, FastifyReply } from 'fastify'; declare module 'fastify' { + interface FastifyInstance { + authenticate: ( + request: FastifyRequest, + reply: FastifyReply + ) => Promise; + } + interface FastifyRequest { cookies: Record; } } + +declare module '@fastify/jwt' { + interface FastifyJWT { + user: { + id: string; + username: string; + }; + } +} From 9a65962439c22fc5b7585dd43a746d86762823ad Mon Sep 17 00:00:00 2001 From: ramnnnn2006 Date: Fri, 12 Jun 2026 19:45:55 +0530 Subject: [PATCH 2/3] refactor(backend): use typed authenticate prehandler and jwt user in analytics routes --- apps/backend/src/routes/analytics.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/backend/src/routes/analytics.ts b/apps/backend/src/routes/analytics.ts index efc22fe5..b6eab259 100644 --- a/apps/backend/src/routes/analytics.ts +++ b/apps/backend/src/routes/analytics.ts @@ -12,14 +12,14 @@ export async function analyticsRoutes( '/overview', { // eslint-disable-next-line @typescript-eslint/unbound-method - preHandler: [async (request, reply) => { const server = request.server as any; 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); return } try { await request.jwtVerify() } catch (e) { reply.status(401).send({ error: 'Unauthorized' }) } }], + preHandler: [app.authenticate], }, async ( request: FastifyRequest, _reply: FastifyReply ) => { - const userId = (request.user as any).id; - const username = (request.user as any).username; + const userId = request.user.id; + const username = request.user.username; const today = new Date(); today.setHours(0, 0, 0, 0); @@ -98,7 +98,7 @@ export async function analyticsRoutes( '/views', { // eslint-disable-next-line @typescript-eslint/unbound-method - preHandler: [async (request, reply) => { const server = request.server as any; 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); return } try { await request.jwtVerify() } catch (e) { reply.status(401).send({ error: 'Unauthorized' }) } }], + preHandler: [app.authenticate], }, async ( request: FastifyRequest<{ @@ -109,7 +109,7 @@ export async function analyticsRoutes( }>, _reply: FastifyReply ) => { - const userId = (request.user as any).id; + const userId = request.user.id; const page = parseInt(request.query.page || '1', 10); const limit = 20; const skip = (page - 1) * limit; From 7b792788c919a283dfea3fdaed932c232bb04104 Mon Sep 17 00:00:00 2001 From: ramnnnn2006 Date: Fri, 12 Jun 2026 19:52:09 +0530 Subject: [PATCH 3/3] refactor(backend): type analytics where clause with prisma cardviewwhereinput --- apps/backend/src/routes/analytics.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/backend/src/routes/analytics.ts b/apps/backend/src/routes/analytics.ts index b6eab259..884c0528 100644 --- a/apps/backend/src/routes/analytics.ts +++ b/apps/backend/src/routes/analytics.ts @@ -1,3 +1,4 @@ +import type { Prisma } from '@prisma/client'; import type { FastifyInstance, FastifyRequest, @@ -114,7 +115,7 @@ export async function analyticsRoutes( const limit = 20; const skip = (page - 1) * limit; - const whereClause: any = { ownerId: userId }; + const whereClause: Prisma.CardViewWhereInput = { ownerId: userId }; if (request.query.cardId) { whereClause.cardId = request.query.cardId;