/** * 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: 'Group name is required' }) } // 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 } })