Create real-time session verification against Authentik: - Add /api/auth/status endpoint that reads Authentik headers live - Modify checkSessionStatus() to fetch from API instead of local state - Show "Verifying..." toast while checking - Sync local state with actual Authentik session status - Handle connection errors gracefully This ensures the status check reflects the current Authentik session, not just the cached local state.
37 lines
914 B
TypeScript
37 lines
914 B
TypeScript
/**
|
|
* API endpoint para verificar el estado de autenticación en tiempo real
|
|
* Consulta los headers inyectados por Authentik Proxy Outpost
|
|
*/
|
|
export default defineEventHandler((event) => {
|
|
// Leer headers de Authentik en tiempo real
|
|
const headers = getHeaders(event)
|
|
|
|
const username = headers['x-authentik-username']
|
|
const email = headers['x-authentik-email']
|
|
const name = headers['x-authentik-name']
|
|
const groups = headers['x-authentik-groups']
|
|
const uid = headers['x-authentik-uid']
|
|
|
|
// Si no hay username, no hay sesión activa en Authentik
|
|
if (!username) {
|
|
return {
|
|
authenticated: false,
|
|
user: null,
|
|
timestamp: new Date().toISOString()
|
|
}
|
|
}
|
|
|
|
// Sesión activa
|
|
return {
|
|
authenticated: true,
|
|
user: {
|
|
username,
|
|
email,
|
|
name,
|
|
groups: groups ? groups.split('|') : [],
|
|
uid
|
|
},
|
|
timestamp: new Date().toISOString()
|
|
}
|
|
})
|