Skip to content

Commit a9dc3bd

Browse files
chore(api): add user's id to errors sent to Sentry (freeCodeCamp#60725)
1 parent 892843f commit a9dc3bd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

api/src/plugins/auth.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ const auth: FastifyPluginCallback = (fastify, _options, done) => {
6767
};
6868

6969
if (isExpired(accessToken)) return setAccessDenied(req, TOKEN_EXPIRED);
70+
// We're using token.userId since it's possible for the user record to be
71+
// malformed and for prisma to throw while trying to find the user.
72+
fastify.Sentry?.setUser({
73+
id: accessToken.userId
74+
});
7075

7176
const user = await fastify.prisma.user.findUnique({
7277
where: { id: accessToken.userId }
@@ -142,6 +147,12 @@ const auth: FastifyPluginCallback = (fastify, _options, done) => {
142147
message: 'Token not found'
143148
};
144149
}
150+
// We're using token.userId since it's possible for the user record to be
151+
// malformed and for prisma to throw while trying to find the user.
152+
153+
fastify.Sentry?.setUser({
154+
id: token.userId
155+
});
145156

146157
const user = await fastify.prisma.user.findUnique({
147158
where: { id: token.userId }

0 commit comments

Comments
 (0)