Actualizar index.html

This commit is contained in:
2026-03-04 15:18:11 +00:00
parent 1c9b9efe14
commit 5c801e6a1f

View File

@@ -81,6 +81,7 @@
lucide.createIcons();
const urlParams = new URLSearchParams(window.location.search);
urlToken = urlParams.get('token');
const serviceParam = urlParams.get('service'); // Por si viene el ID del servicio
if (!urlToken) {
showError();
@@ -88,11 +89,23 @@
}
try {
const res = await fetch(`${API_URL}/public/portal/${urlToken}`);
// Le pasamos el token y opcionalmente el ID del servicio si viene en la URL
let fetchUrl = `${API_URL}/public/portal/${urlToken}`;
if (serviceParam) {
fetchUrl += `?service=${serviceParam}`;
}
const res = await fetch(fetchUrl);
const data = await res.json();
if (!data.ok) throw new Error("Token inválido");
renderPortal(data.client, data.company, data.services);
// Si no hay servicios, no mostramos error, mostramos el portal vacío
const servicesList = data.services || [];
renderPortal(data.client, data.company, servicesList);
} catch (e) {
console.error("Error cargando portal:", e);
showError();
}
});