From 43fda0b20a7b89b938860731a41540c3c8116ec8 Mon Sep 17 00:00:00 2001 From: Darius Date: Wed, 19 Nov 2025 00:54:08 +0100 Subject: [PATCH] fix verification of api key --- src/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5731b05..8ebd9d5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +import { logInfo } from "@dpu/shared/dist/logger.js"; import type { FastifyReply, FastifyRequest } from "fastify"; import fastify from "fastify"; import fastifyAxios from "fastify-axios"; @@ -23,11 +24,15 @@ await server.register(fastifyAxios, { }, }); -function verifyAPIKey(request: FastifyRequest, reply: FastifyReply): void { +async function verifyAPIKey( + request: FastifyRequest, + reply: FastifyReply, +): Promise { const apiKey = request.headers["x-api-key"]; if (!apiKey || apiKey !== Config.api_key) { - reply.code(401).send({ error: "Invalid API key" }); + logInfo("POST Request with wrong API key received"); + return reply.code(401).send({ error: "Invalid API key" }); } }