From d2d5e5ee3675c34fff62b4721e14a8b978d75406 Mon Sep 17 00:00:00 2001 From: Yachika Sharma Date: Sun, 14 Jun 2026 16:54:24 +0530 Subject: [PATCH 1/3] fix: remove any usages in follow.ts, reuse Fastify/JWT types (#550) --- apps/backend/src/routes/follow.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/backend/src/routes/follow.ts b/apps/backend/src/routes/follow.ts index a152fc55..bddb670e 100644 --- a/apps/backend/src/routes/follow.ts +++ b/apps/backend/src/routes/follow.ts @@ -6,11 +6,11 @@ import { followLogSchema } from '../validations/follow.validation.js'; export async function followRoutes(app: FastifyInstance) { app.addHook('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 { const payload = await request.jwtVerify(); if (payload) (request as any).user = payload; } catch (e) { reply.status(401).send({ error: 'Unauthorized' }) } - }); + const server = request.server; + if (typeof server?.authenticate === 'function') { await server.authenticate(request, reply); return } + if (typeof app.authenticate === 'function') { await app.authenticate(request, reply); return } + try { const payload = await request.jwtVerify(); if (payload) request.user = payload; } catch (e) { reply.status(401).send({ error: 'Unauthorized' }) } + }); // ─── Follow via API (Layer 1) ─── // Currently supports: GitHub @@ -19,7 +19,7 @@ export async function followRoutes(app: FastifyInstance) { request: FastifyRequest<{ Params: { platform: string; targetUsername: string } }>, reply: FastifyReply ) => { - const userId = (request.user as any).id; + const userId = request.user.id; const { platform, targetUsername } = request.params; // GitHub follow tokens are stored under 'github_follow' to prevent the @@ -116,7 +116,7 @@ export async function followRoutes(app: FastifyInstance) { }>, reply: FastifyReply ) => { - const userId = (request.user as any).id; + const userId = request.user.id; const { platform, targetUsername } = request.params; const parsed = followLogSchema.safeParse(request.body); @@ -137,8 +137,8 @@ export async function followRoutes(app: FastifyInstance) { }, }); return reply.send({ status: 'success', logId: log.id }); - } catch (error: any) { - app.log.error('Failed to log follow:', error); + } catch (error) { + app.log.error(`Failed to log follow: ${getErrorMessage(error)}`); return reply.status(500).send({ error: 'Failed to log follow event' }); } }); @@ -148,7 +148,7 @@ export async function followRoutes(app: FastifyInstance) { request: FastifyRequest<{ Params: { platform: string; targetUsername: string } }>, reply: FastifyReply ) => { - const userId = (request.user as any).id; + const userId = request.user.id; const { platform, targetUsername } = request.params; await app.prisma.followLog.deleteMany({ From 4f4f74b26bc8db0799413aac9f21765816a66050 Mon Sep 17 00:00:00 2001 From: Yachika Sharma Date: Sun, 14 Jun 2026 17:15:28 +0530 Subject: [PATCH 2/3] fix: type jwtVerify payload with AuthenticatedUser --- apps/backend/src/routes/follow.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/backend/src/routes/follow.ts b/apps/backend/src/routes/follow.ts index bddb670e..8a311920 100644 --- a/apps/backend/src/routes/follow.ts +++ b/apps/backend/src/routes/follow.ts @@ -3,13 +3,14 @@ import { decrypt } from '../utils/encryption.js'; import { getErrorMessage } from '../utils/error.util.js'; import { getPlatform, getProfileUrl, getWebViewUrl } from '@devcard/shared'; import { followLogSchema } from '../validations/follow.validation.js'; +import type { AuthenticatedUser } from '../types/fastify.js'; export async function followRoutes(app: FastifyInstance) { app.addHook('preHandler', async (request, reply) => { const server = request.server; if (typeof server?.authenticate === 'function') { await server.authenticate(request, reply); return } if (typeof app.authenticate === 'function') { await app.authenticate(request, reply); return } - try { const payload = await request.jwtVerify(); if (payload) request.user = payload; } catch (e) { reply.status(401).send({ error: 'Unauthorized' }) } + try { const payload = await request.jwtVerify(); if (payload) request.user = payload; } catch (e) { reply.status(401).send({ error: 'Unauthorized' }) } }); // ─── Follow via API (Layer 1) ─── From 65abec76a4e451be7511a9e0a9aed4452f0d0d37 Mon Sep 17 00:00:00 2001 From: Yachika Sharma Date: Sun, 14 Jun 2026 12:47:12 +0000 Subject: [PATCH 3/3] fix: add explicit return type and rename unused catch variable for ESLint --- apps/backend/src/routes/follow.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/backend/src/routes/follow.ts b/apps/backend/src/routes/follow.ts index 8a311920..0461db3d 100644 --- a/apps/backend/src/routes/follow.ts +++ b/apps/backend/src/routes/follow.ts @@ -1,16 +1,18 @@ -import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'; +import { getPlatform, getProfileUrl, getWebViewUrl } from '@devcard/shared'; + import { decrypt } from '../utils/encryption.js'; import { getErrorMessage } from '../utils/error.util.js'; -import { getPlatform, getProfileUrl, getWebViewUrl } from '@devcard/shared'; import { followLogSchema } from '../validations/follow.validation.js'; + import type { AuthenticatedUser } from '../types/fastify.js'; +import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'; -export async function followRoutes(app: FastifyInstance) { +export async function followRoutes(app: FastifyInstance): Promise { app.addHook('preHandler', async (request, reply) => { const server = request.server; if (typeof server?.authenticate === 'function') { await server.authenticate(request, reply); return } if (typeof app.authenticate === 'function') { await app.authenticate(request, reply); return } - try { const payload = await request.jwtVerify(); if (payload) request.user = payload; } catch (e) { reply.status(401).send({ error: 'Unauthorized' }) } + try { const payload = await request.jwtVerify(); if (payload) {request.user = payload;} } catch (_e) { reply.status(401).send({ error: 'Unauthorized' }) } }); // ─── Follow via API (Layer 1) ───