diff --git a/frontend/panel.html b/frontend/panel.html index a2f5ad6..1926458 100644 --- a/frontend/panel.html +++ b/frontend/panel.html @@ -31,11 +31,12 @@ const { useState, useEffect, useCallback } = React; // ═══════════════════════════════════════════════════════════ const API_BASE = `${window.location.origin}/api`; async function apiFetch(path, options = {}) { - const res = await fetch(`${API_BASE}${path}`, { - credentials: "include", - ...options, - headers: { "Content-Type": "application/json", ...(options.headers || {}) }, - }); + // Content-Type JSON SOLO cuando hay body: Fastify rechaza un cuerpo vacío con + // application/json (FST_ERR_CTP_EMPTY_JSON_BODY → 400), lo que rompía todos los + // POST sin cuerpo (aprobar/baja/rechazar/logout). Con body, el header se pone. + const headers = { ...(options.headers || {}) }; + if (options.body != null) headers["Content-Type"] = "application/json"; + const res = await fetch(`${API_BASE}${path}`, { credentials: "include", ...options, headers }); const data = await res.json().catch(() => ({})); if (!res.ok) { const err = new Error(data.error || `HTTP ${res.status}`);