fix(session): corregir persistencia de sesion en F5 y visibilidad de dashboard de padres
This commit is contained in:
@@ -1952,6 +1952,7 @@
|
||||
<span>Guardar Nuevas Credenciales</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SUBVISTA: DASHBOARD EJECUTIVO FAMILIAR -->
|
||||
<div id="parentSubViewDashboard" class="parent-subview" style="display: none;">
|
||||
|
||||
+30
-2
@@ -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 {
|
||||
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
@@ -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
@@ -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
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user