diff --git a/apps/api/src/routes/event.router.ts b/apps/api/src/routes/event.router.ts index 65f34b93..c821eddf 100644 --- a/apps/api/src/routes/event.router.ts +++ b/apps/api/src/routes/event.router.ts @@ -16,7 +16,12 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => { reply ) => { try { - const projectId = await validateSdkRequest(req.headers); + const projectId = await validateSdkRequest(req.headers).catch( + () => null + ); + if (!projectId) { + return reply.status(401).send(); + } req.projectId = projectId; const bot = req.headers['user-agent'] diff --git a/apps/api/src/routes/profile.router.ts b/apps/api/src/routes/profile.router.ts index baa0de31..d1951e67 100644 --- a/apps/api/src/routes/profile.router.ts +++ b/apps/api/src/routes/profile.router.ts @@ -6,7 +6,10 @@ import type { FastifyPluginCallback } from 'fastify'; const eventRouter: FastifyPluginCallback = (fastify, opts, done) => { fastify.addHook('preHandler', async (req, reply) => { try { - const projectId = await validateSdkRequest(req.headers); + const projectId = await validateSdkRequest(req.headers).catch(() => null); + if (!projectId) { + return reply.status(401).send(); + } req.projectId = projectId; const bot = req.headers['user-agent']