Menu
popagent
publicLatest change 6edc7e928c57dab23c0973ed3f7ee70b3ebb72d5 - Initial popagent baseline by AkurAI Build
import { timingSafeEqual } from "node:crypto";
export function requireApiKey(req: Request): Response | undefined {
const configuredApiKey = process.env.POPAGENT_API_KEY;
if (!configuredApiKey) return undefined;
const supplied = req.headers.get("x-popagent-key") ?? "";
const expected = Buffer.from(configuredApiKey);
const actual = Buffer.from(supplied);
if (actual.length !== expected.length || !timingSafeEqual(actual, expected)) {
return Response.json({ error: "unauthorized" }, { status: 401 });
}
return undefined;
}