All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 2m19s
- Traducir mensajes de API a español - Configurar idioma español en HTML y manifest (lang="es") - Actualizar nombres de app: "Perfil Nucleo" - Crear WindowTitleBar para Window Controls Overlay - Ajustar padding para acomodar barra de título - Traducir campos restantes en componentes legacy
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
/**
|
|
* Endpoint para verificar membresía de grupo desde el backend
|
|
* Valida contra los headers de Authentik en el servidor
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
// Leer el body de la petición
|
|
const body = await readBody(event)
|
|
const { groupName } = body
|
|
|
|
if (!groupName || typeof groupName !== 'string') {
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: 'El nombre del grupo es requerido'
|
|
})
|
|
}
|
|
|
|
// Leer headers de Authentik
|
|
const headers = getHeaders(event)
|
|
const authentikGroups = headers['x-authentik-groups']
|
|
|
|
// Si no hay header de grupos, el usuario no está autenticado o no tiene grupos
|
|
if (!authentikGroups) {
|
|
return {
|
|
hasGroup: false,
|
|
groups: []
|
|
}
|
|
}
|
|
|
|
// Parsear los grupos (separados por |)
|
|
const userGroups = authentikGroups.split('|').filter(g => g.trim())
|
|
|
|
// Verificar si el usuario tiene el grupo solicitado
|
|
const hasGroup = userGroups.includes(groupName)
|
|
|
|
return {
|
|
hasGroup,
|
|
groups: userGroups,
|
|
checkedGroup: groupName
|
|
}
|
|
})
|