From a9dc3bdeef781da2a7c3dbbb367eb46eba27306b Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Mon, 9 Jun 2025 22:21:02 +0200 Subject: [PATCH] chore(api): add user's id to errors sent to Sentry (#60725) --- api/src/plugins/auth.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/api/src/plugins/auth.ts b/api/src/plugins/auth.ts index aa227eae3c6..0212c9e220d 100644 --- a/api/src/plugins/auth.ts +++ b/api/src/plugins/auth.ts @@ -67,6 +67,11 @@ const auth: FastifyPluginCallback = (fastify, _options, done) => { }; if (isExpired(accessToken)) return setAccessDenied(req, TOKEN_EXPIRED); + // We're using token.userId since it's possible for the user record to be + // malformed and for prisma to throw while trying to find the user. + fastify.Sentry?.setUser({ + id: accessToken.userId + }); const user = await fastify.prisma.user.findUnique({ where: { id: accessToken.userId } @@ -142,6 +147,12 @@ const auth: FastifyPluginCallback = (fastify, _options, done) => { message: 'Token not found' }; } + // We're using token.userId since it's possible for the user record to be + // malformed and for prisma to throw while trying to find the user. + + fastify.Sentry?.setUser({ + id: token.userId + }); const user = await fastify.prisma.user.findUnique({ where: { id: token.userId }