mirror of
https://github.com/bitbaum/botsmann.git
synced 2026-12-04 03:47:45 +01:00
- Add @~/.claude/CLAUDE.md import for global engineering standards - Update Last Updated date to 2026-01-23 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
33 lines
872 B
TypeScript
33 lines
872 B
TypeScript
import { createErrorResponse } from '@/lib/schemas/errors';
|
|
|
|
const API_KEY = process.env.API_KEY || 'development-key';
|
|
|
|
export async function validateApiKey(req: Request) {
|
|
// Skip validation during build time or static generation
|
|
if (
|
|
process.env.NEXT_PHASE === 'phase-production-build' ||
|
|
process.env.NEXT_PHASE === 'phase-static-generation'
|
|
) {
|
|
return;
|
|
}
|
|
|
|
const apiKey = req.headers.get('x-api-key');
|
|
|
|
if (!apiKey) {
|
|
return new Response(
|
|
JSON.stringify(createErrorResponse('API key is required', 'UNAUTHORIZED')),
|
|
{
|
|
status: 401,
|
|
headers: { 'Content-Type': 'application/json' },
|
|
},
|
|
);
|
|
}
|
|
|
|
if (apiKey !== API_KEY) {
|
|
return new Response(JSON.stringify(createErrorResponse('Invalid API key', 'UNAUTHORIZED')), {
|
|
status: 401,
|
|
headers: { 'Content-Type': 'application/json' },
|
|
});
|
|
}
|
|
}
|