fix: actually send the N8N_AUTH_TOKEN header to n8n
All checks were successful
Build and Deploy / build-and-push (push) Successful in 53s

This commit is contained in:
Cauê Faleiros
2026-04-09 11:33:25 -03:00
parent a6ba7559d1
commit 9fdd15e292

View File

@@ -2,6 +2,7 @@ import axios from 'axios';
export const sendToN8n = async (data: any): Promise<void> => {
const n8nWebhookUrl = process.env.N8N_WEBHOOK_URL;
const n8nAuthToken = process.env.N8N_AUTH_TOKEN;
if (!n8nWebhookUrl) {
console.error('N8N_WEBHOOK_URL is not defined in environment variables.');
@@ -10,11 +11,17 @@ export const sendToN8n = async (data: any): Promise<void> => {
try {
console.log(`Forwarding payload to n8n at ${n8nWebhookUrl}...`);
const response = await axios.post(n8nWebhookUrl, data, {
headers: {
'Content-Type': 'application/json'
}
});
const headers: Record<string, string> = {
'Content-Type': 'application/json'
};
if (n8nAuthToken) {
// Send exactly what the user typed in the environment variable
headers['Authorization'] = n8nAuthToken;
}
const response = await axios.post(n8nWebhookUrl, data, { headers });
console.log(`Successfully forwarded to n8n. Status: ${response.status}`);
} catch (error: any) {
console.error('Failed to forward payload to n8n.', error.message);