This commit is contained in:
alma 2025-05-22 18:52:59 +02:00
parent 4fa5182abb
commit 2868f8ba95
2 changed files with 18 additions and 6 deletions

View File

@ -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' };
}

View File

@ -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'
}
};