Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

better handling unauth request

Carl-Gerhard Lindesvärd4b3ce772ba84
diff --git a/apps/api/src/routes/event.router.ts b/apps/api/src/routes/event.router.ts
index 65f34b938..c821eddfb 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 baa0de31b..d1951e67d 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']