diff --git a/app/api/missions/route.ts b/app/api/missions/route.ts index 9be8778e..9f663920 100644 --- a/app/api/missions/route.ts +++ b/app/api/missions/route.ts @@ -15,13 +15,24 @@ interface MissionUserInput { // Helper function to check authentication async function checkAuth(request: Request) { - // Check for API key first + // Check for API key in headers first const apiKey = request.headers.get('x-api-key'); - console.log('Received API key:', apiKey); - console.log('Expected API key:', process.env.N8N_API_KEY); - console.log('API key match:', apiKey === process.env.N8N_API_KEY); + console.log('Received API key from headers:', apiKey); - if (apiKey === process.env.N8N_API_KEY) { + // If no API key in headers, try to get it from the request body + let bodyApiKey = null; + if (request.method === 'POST') { + const body = await request.clone().json(); + bodyApiKey = body?.config?.N8N_API_KEY; + console.log('Received API key from body:', bodyApiKey); + } + + const receivedApiKey = apiKey || bodyApiKey; + console.log('Final API key used:', receivedApiKey); + console.log('Expected API key:', process.env.N8N_API_KEY); + console.log('API key match:', receivedApiKey === process.env.N8N_API_KEY); + + if (receivedApiKey === process.env.N8N_API_KEY) { return { authorized: true, userId: 'system' }; } diff --git a/lib/services/n8n-service.ts b/lib/services/n8n-service.ts index 06cb2f11..819f0aa7 100644 --- a/lib/services/n8n-service.ts +++ b/lib/services/n8n-service.ts @@ -25,7 +25,8 @@ export class N8nService { participation: data.participation || 'default', config: { ...data.config, - N8N_API_KEY: this.apiKey + N8N_API_KEY: this.apiKey, + MISSION_API_URL: process.env.NEXT_PUBLIC_API_URL || 'https://localhost:3000/api' } };