n8n
This commit is contained in:
parent
7465efad5a
commit
cb46c03db5
@ -17,9 +17,19 @@ async function checkAuth(request: Request, body?: any) {
|
|||||||
if (apiKey === process.env.N8N_API_KEY) {
|
if (apiKey === process.env.N8N_API_KEY) {
|
||||||
// For service account, use the creatorId from the request body
|
// For service account, use the creatorId from the request body
|
||||||
if (body?.creatorId) {
|
if (body?.creatorId) {
|
||||||
|
console.log('Using creatorId from request body:', body.creatorId);
|
||||||
|
// Verify the user exists
|
||||||
|
const user = await prisma.user.findUnique({
|
||||||
|
where: { id: body.creatorId }
|
||||||
|
});
|
||||||
|
if (!user) {
|
||||||
|
console.error('Creator user not found:', body.creatorId);
|
||||||
|
return { authorized: false, userId: null };
|
||||||
|
}
|
||||||
return { authorized: true, userId: body.creatorId };
|
return { authorized: true, userId: body.creatorId };
|
||||||
}
|
}
|
||||||
// Fallback to system user if no creatorId provided
|
// Fallback to system user if no creatorId provided
|
||||||
|
console.log('No creatorId provided, using system user');
|
||||||
return { authorized: true, userId: process.env.SYSTEM_USER_ID || 'system' };
|
return { authorized: true, userId: process.env.SYSTEM_USER_ID || 'system' };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,8 @@ export class N8nService {
|
|||||||
try {
|
try {
|
||||||
console.log('Triggering n8n workflow for mission creation:', {
|
console.log('Triggering n8n workflow for mission creation:', {
|
||||||
name: missionData.name,
|
name: missionData.name,
|
||||||
missionType: missionData.missionType
|
missionType: missionData.missionType,
|
||||||
|
webhookUrl: this.webhookUrl
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await axios.post(this.webhookUrl, missionData, {
|
const response = await axios.post(this.webhookUrl, missionData, {
|
||||||
@ -25,7 +26,11 @@ export class N8nService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('n8n workflow response:', response.data);
|
console.log('n8n workflow response:', {
|
||||||
|
status: response.status,
|
||||||
|
statusText: response.statusText,
|
||||||
|
data: response.data
|
||||||
|
});
|
||||||
|
|
||||||
if (response.data.errors && response.data.errors.length > 0) {
|
if (response.data.errors && response.data.errors.length > 0) {
|
||||||
console.warn('Workflow completed with partial success:', response.data.errors);
|
console.warn('Workflow completed with partial success:', response.data.errors);
|
||||||
@ -33,12 +38,19 @@ export class N8nService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!response.data.success) {
|
if (!response.data.success) {
|
||||||
|
console.error('Workflow execution failed:', {
|
||||||
|
message: response.data.message,
|
||||||
|
data: response.data
|
||||||
|
});
|
||||||
throw new Error(`Workflow execution failed: ${response.data.message || 'Unknown error'}`);
|
throw new Error(`Workflow execution failed: ${response.data.message || 'Unknown error'}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error triggering n8n workflow:', error);
|
console.error('Error triggering n8n workflow:', {
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
webhookUrl: this.webhookUrl
|
||||||
|
});
|
||||||
throw new Error(`Failed to trigger mission creation workflow: ${error instanceof Error ? error.message : String(error)}`);
|
throw new Error(`Failed to trigger mission creation workflow: ${error instanceof Error ? error.message : String(error)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user