diff --git a/nuxt4/app/composables/useAuthentik.ts b/nuxt4/app/composables/useAuthentik.ts index 4a88c54..1160550 100644 --- a/nuxt4/app/composables/useAuthentik.ts +++ b/nuxt4/app/composables/useAuthentik.ts @@ -53,6 +53,18 @@ export const useAuthentik = () => { const checkSessionStatus = async () => { const toast = useToast() + // Verificar si está offline primero + if (!navigator.onLine) { + toast.add({ + title: 'Modo Offline', + description: 'No se puede validar sesión sin conexión', + color: 'gray', + icon: 'i-heroicons-wifi', + timeout: 5000 + }) + return + } + // Mostrar toast de "verificando..." toast.add({ title: 'Verificando sesión...', @@ -93,6 +105,18 @@ export const useAuthentik = () => { }) } } catch (error) { + // Verificar si está offline ahora (pudo desconectarse durante la petición) + if (!navigator.onLine) { + toast.add({ + title: 'Modo Offline', + description: 'No se puede validar sesión sin conexión', + color: 'gray', + icon: 'i-heroicons-wifi', + timeout: 5000 + }) + return + } + // Si el error es por redirect de Authentik (CORS/fetch error), significa que no hay sesión // Authentik redirige a login cuando no hay sesión válida, causando error CORS en fetch const errorMessage = error?.message || error?.toString() || '' diff --git a/nuxt4/nuxt.config.ts b/nuxt4/nuxt.config.ts index cedd434..3467460 100644 --- a/nuxt4/nuxt.config.ts +++ b/nuxt4/nuxt.config.ts @@ -72,22 +72,15 @@ export default defineNuxtConfig({ ] }, workbox: { - navigateFallback: undefined, - globPatterns: ['**/*.{js,css,html,png,svg,ico}'], + navigateFallback: '/', + globPatterns: ['**/*.{js,css,html,png,svg,ico,json}'], cleanupOutdatedCaches: true, runtimeCaching: [ { urlPattern: /^https:\/\/authentik\.nucleoriofrio\.com\/.*/i, - handler: 'NetworkFirst', + handler: 'NetworkOnly', options: { - cacheName: 'authentik-api-cache', - expiration: { - maxEntries: 10, - maxAgeSeconds: 60 * 60 * 24 // 24 hours - }, - cacheableResponse: { - statuses: [0, 200] - } + networkTimeoutSeconds: 10 } } ] diff --git a/nuxt4/server/api/auth/status.get.ts b/nuxt4/server/api/auth/status.get.ts index e156bd8..f892a47 100644 --- a/nuxt4/server/api/auth/status.get.ts +++ b/nuxt4/server/api/auth/status.get.ts @@ -3,6 +3,13 @@ * Consulta los headers inyectados por Authentik Proxy Outpost */ export default defineEventHandler((event) => { + // Establecer headers para prevenir caching + setResponseHeaders(event, { + 'Cache-Control': 'no-store, no-cache, must-revalidate, proxy-revalidate', + 'Pragma': 'no-cache', + 'Expires': '0' + }) + // Leer headers de Authentik en tiempo real const headers = getHeaders(event)