Add API_KEYS_ACTIVE toggle to API key middleware

This commit is contained in:
NeilClack
2026-07-19 08:44:10 -05:00
parent cca26c0578
commit 74896234f9
+3
View File
@@ -2,12 +2,14 @@ import { auth } from '$lib/auth';
import { svelteKitHandler } from 'better-auth/svelte-kit';
import { building } from '$app/environment';
import { validateApiKey } from '$lib/server/api-key';
import { env } from '$env/dynamic/private';
export async function handle({ event, resolve }) {
if (
event.url.pathname.startsWith('/api/v1/') &&
!event.url.pathname.startsWith('/api/v1/automations/')
) {
if (env.API_KEYS_ACTIVE !== 'false') {
const authHeader = event.request.headers.get('authorization');
if (!authHeader?.startsWith('Bearer ')) {
return new Response(JSON.stringify({ error: 'API key required' }), {
@@ -24,6 +26,7 @@ export async function handle({ event, resolve }) {
headers: { 'content-type': 'application/json' }
});
}
}
return resolve(event);
}