Files
perfil/nuxt4/app/server/api/authentik/user.get.ts
josedario87 248af8f8d1
All checks were successful
build-and-deploy / build (push) Successful in 58s
build-and-deploy / deploy (push) Successful in 3s
Initial commit: Add Nuxt app with Authentik integration and profile editing
- Add Nuxt 4 application with Authentik Proxy Outpost integration
- Add EditProfileButton component for editing user profile via Authentik API
- Add API endpoints for Authentik user management (GET/PATCH)
- Configure Gitea Actions workflow for automated deployment
- Add monitoring hook for Gitea Actions
- Configure environment variables and Docker Compose setup
2025-10-16 17:14:49 -06:00

58 lines
1.6 KiB
TypeScript

/**
* Obtiene la información del usuario actual desde Authentik
*/
export default defineEventHandler(async (event) => {
const config = useRuntimeConfig()
const headers = getRequestHeaders(event)
// Obtener el username desde los headers de Authentik
const username = headers['x-authentik-username']
if (!username) {
throw createError({
statusCode: 401,
message: 'Usuario no autenticado'
})
}
// Obtener la URL y token de Authentik desde variables de entorno
const authentikUrl = config.authentikApiUrl || config.public.authentikUrl
const authentikToken = config.authentikApiToken
if (!authentikToken) {
throw createError({
statusCode: 500,
message: 'Token de Authentik no configurado'
})
}
try {
// Consultar la API de Authentik para obtener información detallada del usuario
const response = await $fetch(`${authentikUrl}/api/v3/core/users/?username=${username}`, {
headers: {
'Authorization': `Bearer ${authentikToken}`,
'Content-Type': 'application/json'
}
})
// La API devuelve un array de resultados
const users = response as any
if (!users.results || users.results.length === 0) {
throw createError({
statusCode: 404,
message: 'Usuario no encontrado'
})
}
// Devolver el primer resultado (debería ser único por username)
return users.results[0]
} catch (error: any) {
console.error('Error al obtener usuario de Authentik:', error)
throw createError({
statusCode: error.statusCode || 500,
message: error.message || 'Error al obtener información del usuario'
})
}
})