- Integrated Authentik OAuth/OIDC authentication - Added PWA functionality with offline support - Created protected and public API endpoints - Configured Docker deployment with Traefik - Added Gitea Actions CI/CD workflow - Included comprehensive setup documentation
26 lines
866 B
TypeScript
26 lines
866 B
TypeScript
/**
|
|
* Auth Middleware
|
|
*
|
|
* Protege rutas que requieren autenticación
|
|
* Uso: Añade definePageMeta({ middleware: 'auth' }) en las páginas que necesites proteger
|
|
*/
|
|
export default defineNuxtRouteMiddleware((to, from) => {
|
|
const { loggedIn } = useUserSession()
|
|
|
|
// Si el usuario no está autenticado y no está en modo offline
|
|
if (!loggedIn.value) {
|
|
// Verificar si hay conexión
|
|
if (import.meta.client && !navigator.onLine) {
|
|
// En modo offline, permitir navegación si hay datos en caché
|
|
console.log('Modo offline: permitiendo navegación con datos en caché')
|
|
return
|
|
}
|
|
|
|
// Guardar la ruta a la que quería acceder para redirigir después del login
|
|
const redirectPath = to.fullPath
|
|
|
|
// Redirigir al login con la ruta de destino
|
|
return navigateTo(`/login?redirect=${encodeURIComponent(redirectPath)}`)
|
|
}
|
|
})
|