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
This commit is contained in:
57
nuxt4/app/server/api/authentik/user.get.ts
Normal file
57
nuxt4/app/server/api/authentik/user.get.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* 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'
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user