From 972dc80c78aa2f02f038d53b281d32a498c800f7 Mon Sep 17 00:00:00 2001 From: lizandrogd <77708265+lizandrogd@users.noreply.github.com> Date: Wed, 21 Jan 2026 15:03:27 -0500 Subject: [PATCH] up --- conversations.php | 9 ++++++++- index.php | 32 +++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/conversations.php b/conversations.php index ba728a8..6a23b94 100644 --- a/conversations.php +++ b/conversations.php @@ -550,10 +550,17 @@ async loadNotifications() { try { - const resp = await fetch('api/get_notifications.php'); + const resp = await fetch('api/get_notifications.php', { credentials: 'same-origin' }); + if (resp.status === 401) { + console.warn('Notifications fetch: unauthorized (session may have expired)'); + return; + } const json = await resp.json(); + console.debug('loadNotifications response:', json); if (json && json.success && Array.isArray(json.data)) { json.data.forEach(n => this.showNotificationToast(n)); + } else if (json && json.success === false) { + console.warn('get_notifications returned error:', json.error || json); } } catch (e) { console.error('Error loading notifications', e); diff --git a/index.php b/index.php index 5dad300..3b82e2f 100644 --- a/index.php +++ b/index.php @@ -958,8 +958,14 @@ try { }, async loadNotifications() { try { - const resp = await fetch('api/get_notifications.php'); + const resp = await fetch('api/get_notifications.php', { credentials: 'same-origin' }); + if (resp.status === 401) { + console.warn('Notifications fetch: unauthorized (session may have expired)'); + this.showSessionExpiredToast(); + return; + } const json = await resp.json(); + console.debug('NotificationManager.loadNotifications response:', json); if (json && json.success && Array.isArray(json.data)) { const unreadCount = json.data.length; if (unreadCount > 0) { @@ -969,11 +975,35 @@ try { this.countEl.style.display = 'none'; } json.data.forEach(n => this.showToast(n)); + } else if (json && json.success === false) { + console.warn('Notification API error:', json.error || json); } } catch (e) { console.error('Error loading global notifications', e); } }, + showSessionExpiredToast() { + const toast = document.createElement('div'); + toast.className = 'notification-toast'; + toast.style.background = '#fff7f7'; + toast.style.border = '1px solid #f5c6cb'; + toast.style.padding = '10px 14px'; + toast.style.marginTop = '8px'; + toast.style.borderRadius = '6px'; + toast.style.minWidth = '220px'; + const msg = document.createElement('div'); + msg.textContent = 'La sesión ha expirado. Por favor, vuelve a iniciar sesión.'; + toast.appendChild(msg); + const btn = document.createElement('button'); + btn.className = 'btn btn-sm btn-primary'; + btn.textContent = 'Ir a login'; + btn.onclick = () => { window.location.href = 'login.php'; }; + const actions = document.createElement('div'); + actions.style.marginTop = '8px'; + actions.appendChild(btn); + toast.appendChild(actions); + this.toastsContainer.appendChild(toast); + } showToast(notification) { const toast = document.createElement('div'); toast.className = 'notification-toast';