From 8485618726308bd68e2d3f9accd0584b52b99d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Fri, 12 Apr 2024 20:50:17 +0200 Subject: [PATCH] better logging for sdk auth --- apps/api/src/routes/event.router.ts | 2 +- apps/api/src/routes/profile.router.ts | 4 +++- apps/api/src/utils/auth.ts | 12 ++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/apps/api/src/routes/event.router.ts b/apps/api/src/routes/event.router.ts index c821eddf..54343f65 100644 --- a/apps/api/src/routes/event.router.ts +++ b/apps/api/src/routes/event.router.ts @@ -17,7 +17,7 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => { ) => { try { const projectId = await validateSdkRequest(req.headers).catch( - () => null + req.log.error ); if (!projectId) { return reply.status(401).send(); diff --git a/apps/api/src/routes/profile.router.ts b/apps/api/src/routes/profile.router.ts index d1951e67..2ad932f1 100644 --- a/apps/api/src/routes/profile.router.ts +++ b/apps/api/src/routes/profile.router.ts @@ -6,7 +6,9 @@ import type { FastifyPluginCallback } from 'fastify'; const eventRouter: FastifyPluginCallback = (fastify, opts, done) => { fastify.addHook('preHandler', async (req, reply) => { try { - const projectId = await validateSdkRequest(req.headers).catch(() => null); + const projectId = await validateSdkRequest(req.headers).catch( + req.log.error + ); if (!projectId) { return reply.status(401).send(); } diff --git a/apps/api/src/utils/auth.ts b/apps/api/src/utils/auth.ts index 58f135b0..0f99786d 100644 --- a/apps/api/src/utils/auth.ts +++ b/apps/api/src/utils/auth.ts @@ -23,11 +23,6 @@ export async function validateSdkRequest( const clientSecret = clientSecretNew || clientSecretOld; const origin = headers.origin; - // Temp log - logger.info( - { clientId, origin: origin ? origin : 'empty' }, - 'validateSdkRequest' - ); if (!clientId) { throw new Error('Ingestion: Missing client id'); @@ -69,7 +64,12 @@ export async function validateSdkRequest( } } - throw new Error('Ingestion: Invalid client secret'); + logger.error({ + client, + headers, + origin, + }); + throw new Error('Ingestion: Invalid cors or secret'); } export async function validateExportRequest(