Initial commit: Add Nuxt app with Authentik integration and profile editing
All checks were successful
build-and-deploy / build (push) Successful in 58s
build-and-deploy / deploy (push) Successful in 3s

- 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:
2025-10-16 17:14:49 -06:00
parent 43bcf4a647
commit 248af8f8d1
8 changed files with 366 additions and 1 deletions

View 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'
})
}
})

View File

@@ -0,0 +1,74 @@
/**
* Actualiza la información del usuario en 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'
})
}
// Leer el body de la petición
const body = await readBody(event)
try {
// Primero, obtener el ID del usuario
const usersResponse = await $fetch(`${authentikUrl}/api/v3/core/users/?username=${username}`, {
headers: {
'Authorization': `Bearer ${authentikToken}`,
'Content-Type': 'application/json'
}
})
const users = usersResponse as any
if (!users.results || users.results.length === 0) {
throw createError({
statusCode: 404,
message: 'Usuario no encontrado'
})
}
const userId = users.results[0].pk
// Actualizar el usuario
const updateResponse = await $fetch(`${authentikUrl}/api/v3/core/users/${userId}/`, {
method: 'PATCH',
headers: {
'Authorization': `Bearer ${authentikToken}`,
'Content-Type': 'application/json'
},
body: {
name: body.name,
// Otros campos que se puedan actualizar
...(body.email && { email: body.email })
}
})
return updateResponse
} catch (error: any) {
console.error('Error al actualizar usuario en Authentik:', error)
throw createError({
statusCode: error.statusCode || 500,
message: error.message || 'Error al actualizar información del usuario'
})
}
})