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({