mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
feat(api): add public user route logs (#59124)
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user