From 4b3ce772ba84a859be8fface3405e602de1b63ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Wed, 13 Mar 2024 12:06:43 +0100 Subject: [PATCH] better handling unauth request --- apps/api/src/routes/event.router.ts | 7 ++++++- apps/api/src/routes/profile.router.ts | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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']