fix(session): corregir persistencia de sesion en F5 y visibilidad de dashboard de padres

This commit is contained in:
unknown
2026-10-08 15:44:55 -06:00
parent 7f9c203453
commit 18e91d95c9
5 changed files with 38 additions and 9 deletions
+3 -2
View File
@@ -1952,9 +1952,10 @@
<span>Guardar Nuevas Credenciales</span>
</button>
</div>
</div>
<!-- SUBVISTA: DASHBOARD EJECUTIVO FAMILIAR -->
<div id="parentSubViewDashboard" class="parent-subview" style="display: none;">
<!-- SUBVISTA: DASHBOARD EJECUTIVO FAMILIAR -->
<div id="parentSubViewDashboard" class="parent-subview" style="display: none;">
<div class="parent-subview-header">
<button type="button" onclick="closeParentSubView()" class="parent-subview-back-btn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>
+31 -3
View File
@@ -68,7 +68,7 @@ document.addEventListener('DOMContentLoaded', async () => {
// Registrar Service Worker para PWA
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js?v=13.1').then(reg => {
navigator.serviceWorker.register('/sw.js?v=15.0').then(reg => {
reg.update().catch(() => {});
if ('Notification' in window && Notification.permission === 'granted') {
subscribeDeviceToWebPush().catch(() => {});
@@ -84,6 +84,12 @@ document.addEventListener('DOMContentLoaded', async () => {
localStorage.removeItem('recreopay_token');
localStorage.removeItem('recreopay_user');
sessionStorage.clear();
// Limpiar ?logout=true de la URL para que no persista en el navegador y no vuelva a cerrar sesión en F5
try {
if (window.history && window.history.replaceState) {
window.history.replaceState({}, document.title, window.location.pathname);
}
} catch (e) {}
}
// Verificar si hay sesión activa guardada
@@ -100,7 +106,11 @@ document.addEventListener('DOMContentLoaded', async () => {
// Mostrar pantalla de Login limpia (NO auto-login)
showLoginView();
} else {
await applyUserRoleSession();
try {
await applyUserRoleSession();
} catch (errRole) {
console.error('Error aplicando rol de usuario en sesión:', errRole);
}
}
initStudentSSE();
@@ -416,6 +426,13 @@ async function handleLoginSubmit(event) {
localStorage.setItem('sibopay_user', JSON.stringify(currentUser));
localStorage.setItem('recreopay_user', JSON.stringify(currentUser));
// Limpiar preventivamente cualquier parámetro residual de logout en la URL
try {
if (window.history && window.history.replaceState) {
window.history.replaceState({}, document.title, window.location.pathname);
}
} catch (e) {}
if (window.sounds) window.sounds.playSuccess();
await applyUserRoleSession();
} catch (err) {
@@ -618,6 +635,11 @@ function logout(skipConfirm = false) {
currentStudent = null;
currentParentChild = null;
adminSelectedStudent = null;
try {
if (window.history && window.history.replaceState) {
window.history.replaceState({}, document.title, window.location.pathname);
}
} catch (e) {}
showLoginView();
if (window.sounds) window.sounds.playTap();
}
@@ -3060,6 +3082,11 @@ async function cargarDashboardPadres() {
const data = await res.json();
const resumen = data.resumen || {};
if (data.hijos && data.hijos.length > 0 && (!currentUser.hijos || currentUser.hijos.length === 0)) {
currentUser.hijos = data.hijos;
poblarSelectorHijosDashboardPadres();
}
// 1. KPI Saldo
const elSaldo = document.getElementById('parentDashKpiSaldo');
if (elSaldo) elSaldo.textContent = `₡${(resumen.saldo_disponible || 0).toLocaleString('es-CR')}`;
@@ -3206,7 +3233,8 @@ function closeParentSubView(shouldScroll = true) {
'parentSubViewAlergias',
'parentSubViewLimites',
'parentSubViewHistorial',
'parentSubViewCredenciales'
'parentSubViewCredenciales',
'parentSubViewDashboard'
];
subViews.forEach(id => {
const el = document.getElementById(id);
+1 -1
View File
@@ -2440,7 +2440,7 @@ function posLogout() {
localStorage.removeItem('recreopay_user');
sessionStorage.clear();
} catch (e) {}
window.location.href = '/index.html?logout=true';
window.location.href = '/index.html';
}
window.posLogout = posLogout;
+1 -1
View File
@@ -78,7 +78,7 @@
localStorage.removeItem('recreopay_user');
sessionStorage.clear();
} catch (e) {}
window.location.href = '/index.html?logout=true';
window.location.href = '/index.html';
}
window.posLogout = posLogout;
</script>
+2 -2
View File
@@ -1,5 +1,5 @@
// SiboPay PWA Service Worker v14.0 - Dashboard Ejecutivo de Padres
const CACHE_NAME = 'sibopay-v14.0';
// SiboPay PWA Service Worker v15.0 - Dashboard Ejecutivo de Padres & Persistencia Sesión F5
const CACHE_NAME = 'sibopay-v15.0';
const STATIC_ASSETS = [
'/',
'/index.html',