From 6af8c1005e5fa21603dab2651776f20b16b3fc64 Mon Sep 17 00:00:00 2001 From: Shaun Hamilton Date: Tue, 4 Mar 2025 17:50:18 +0200 Subject: [PATCH] feat(api): add public user route logs (#59124) --- api/src/routes/public/user.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api/src/routes/public/user.ts b/api/src/routes/public/user.ts index 883039a0425..62f4da7b4f5 100644 --- a/api/src/routes/public/user.ts +++ b/api/src/routes/public/user.ts @@ -120,6 +120,8 @@ export const userPublicGetRoutes: FastifyPluginCallbackTypebox = ( } }, async (req, reply) => { + const logger = fastify.log.child({ req }); + logger.info({ username: req.query.username }); // TODO(Post-MVP): look for duplicates unless we can make username unique in the db. const user = await fastify.prisma.user.findFirst({ where: { username: req.query.username } @@ -128,6 +130,7 @@ export const userPublicGetRoutes: FastifyPluginCallbackTypebox = ( }); if (!user) { + logger.warn('User not found'); void reply.code(404); return reply.send({}); } @@ -216,7 +219,10 @@ export const userPublicGetRoutes: FastifyPluginCallbackTypebox = ( attachValidation: true }, async (req, reply) => { + const logger = fastify.log.child({ req }); + if (req.validationError) { + logger.warn({ validationError: req.validationError }); void reply.code(400); // TODO(Post-MVP): return a message telling the requester that their // request was malformed. @@ -225,7 +231,10 @@ export const userPublicGetRoutes: FastifyPluginCallbackTypebox = ( const username = req.query.username.toLowerCase(); - if (isRestricted(username)) return await reply.send({ exists: true }); + if (isRestricted(username)) { + logger.info({ username }, 'Restricted username'); + return await reply.send({ exists: true }); + } const exists = (await fastify.prisma.user.count({