feat(api): add public user route logs (#59124)

This commit is contained in:
Shaun Hamilton
2025-03-04 17:50:18 +02:00
committed by GitHub
parent 4c6b380272
commit 6af8c1005e
+10 -1
View File
@@ -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({