W n8n
This commit is contained in:
parent
4fa5182abb
commit
2868f8ba95
@ -15,13 +15,24 @@ interface MissionUserInput {
|
|||||||
|
|
||||||
// Helper function to check authentication
|
// Helper function to check authentication
|
||||||
async function checkAuth(request: Request) {
|
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');
|
const apiKey = request.headers.get('x-api-key');
|
||||||
console.log('Received API key:', apiKey);
|
console.log('Received API key from headers:', 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) {
|
// 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' };
|
return { authorized: true, userId: 'system' };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,7 +25,8 @@ export class N8nService {
|
|||||||
participation: data.participation || 'default',
|
participation: data.participation || 'default',
|
||||||
config: {
|
config: {
|
||||||
...data.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'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user