Add modular group verification system with frontend and backend checks
This commit implements a comprehensive, reusable group verification system: Components: - GroupCheckButton: Base component for group verification - 7 specialized buttons: 3 real groups (authentik Admins, grupo-prueba, lvl0), 1 public access test, 2 system verification buttons - All buttons support both frontend and backend verification modes Backend: - New API endpoint /api/auth/check-group for server-side group validation - Reads Authentik headers and validates group membership Frontend: - Enhanced useAuthentik composable with hasGroup() and checkGroupBackend() methods - Toast notifications for all verification results - Smooth animations and color-coded visual feedback UI Improvements: - Organized layout with cards for different verification types - Grid layout for group buttons - Professional styling with hover effects and shadows - Clear visual distinction between frontend/backend checks
This commit is contained in:
40
nuxt4/server/api/auth/check-group.post.ts
Normal file
40
nuxt4/server/api/auth/check-group.post.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user