diff --git a/app/api/missions/route.ts b/app/api/missions/route.ts index eda71d63..46d91302 100644 --- a/app/api/missions/route.ts +++ b/app/api/missions/route.ts @@ -15,6 +15,17 @@ interface MissionUserInput { // Helper function to check authentication async function checkAuth(request: Request) { + // Check for API key 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); + + if (apiKey === process.env.N8N_API_KEY) { + return { authorized: true, userId: 'system' }; + } + + // If no API key, check for session const session = await getServerSession(authOptions); if (!session?.user?.id) { console.error('Unauthorized access attempt:', {