diff --git a/nuxt4/app/app.vue b/nuxt4/app/app.vue
index 0d640f8..e37e66a 100644
--- a/nuxt4/app/app.vue
+++ b/nuxt4/app/app.vue
@@ -22,6 +22,9 @@
+
+ Acciones de Sesión
+
+
+
+
+
+
+
+
Verificación de Sistema
+
+
+
+
+
+
+
+
+
+
+
Grupos (Frontend)
+
+
+
+
+
+
+
+
+
+
+
Grupos (Backend)
+
+
+
+
diff --git a/nuxt4/app/components/auth/BackendVerificationButton.vue b/nuxt4/app/components/auth/BackendVerificationButton.vue
new file mode 100644
index 0000000..a3cf8c0
--- /dev/null
+++ b/nuxt4/app/components/auth/BackendVerificationButton.vue
@@ -0,0 +1,82 @@
+
+
+
+
+
+ Verificación Backend
+
+
+
+
+
+
diff --git a/nuxt4/app/components/auth/CheckAuthentikAdminsButton.vue b/nuxt4/app/components/auth/CheckAuthentikAdminsButton.vue
new file mode 100644
index 0000000..f5a016d
--- /dev/null
+++ b/nuxt4/app/components/auth/CheckAuthentikAdminsButton.vue
@@ -0,0 +1,20 @@
+
+
+
+
+
diff --git a/nuxt4/app/components/auth/CheckGrupoPruebaButton.vue b/nuxt4/app/components/auth/CheckGrupoPruebaButton.vue
new file mode 100644
index 0000000..b431160
--- /dev/null
+++ b/nuxt4/app/components/auth/CheckGrupoPruebaButton.vue
@@ -0,0 +1,20 @@
+
+
+
+
+
diff --git a/nuxt4/app/components/auth/CheckLvl0Button.vue b/nuxt4/app/components/auth/CheckLvl0Button.vue
new file mode 100644
index 0000000..6591814
--- /dev/null
+++ b/nuxt4/app/components/auth/CheckLvl0Button.vue
@@ -0,0 +1,20 @@
+
+
+
+
+
diff --git a/nuxt4/app/components/auth/CheckPublicAccessButton.vue b/nuxt4/app/components/auth/CheckPublicAccessButton.vue
new file mode 100644
index 0000000..120f006
--- /dev/null
+++ b/nuxt4/app/components/auth/CheckPublicAccessButton.vue
@@ -0,0 +1,20 @@
+
+
+
+
+
diff --git a/nuxt4/app/components/auth/FrontendVerificationButton.vue b/nuxt4/app/components/auth/FrontendVerificationButton.vue
new file mode 100644
index 0000000..ed93d56
--- /dev/null
+++ b/nuxt4/app/components/auth/FrontendVerificationButton.vue
@@ -0,0 +1,59 @@
+
+
+
+
+
+ Verificación Frontend
+
+
+
+
+
+
diff --git a/nuxt4/app/components/auth/GroupCheckButton.vue b/nuxt4/app/components/auth/GroupCheckButton.vue
new file mode 100644
index 0000000..bf44d05
--- /dev/null
+++ b/nuxt4/app/components/auth/GroupCheckButton.vue
@@ -0,0 +1,112 @@
+
+
+
+
+
+ {{ label }}
+
+
+
+
+
+
diff --git a/nuxt4/app/composables/useAuthentik.ts b/nuxt4/app/composables/useAuthentik.ts
index 3a78b1f..00e079f 100644
--- a/nuxt4/app/composables/useAuthentik.ts
+++ b/nuxt4/app/composables/useAuthentik.ts
@@ -182,11 +182,39 @@ export const useAuthentik = () => {
}
}
+ /**
+ * Verifica si el usuario pertenece a un grupo específico (frontend)
+ * Lee los grupos desde el estado local (headers de Authentik)
+ */
+ const hasGroup = (groupName: string): boolean => {
+ if (!user.value) return false
+ return user.value.groups.includes(groupName)
+ }
+
+ /**
+ * Verifica si el usuario pertenece a un grupo específico (backend)
+ * Consulta al servidor para validar contra Authentik
+ */
+ const checkGroupBackend = async (groupName: string): Promise => {
+ try {
+ const response = await $fetch<{ hasGroup: boolean }>(`/api/auth/check-group`, {
+ method: 'POST',
+ body: { groupName }
+ })
+ return response.hasGroup
+ } catch (error) {
+ console.error('Error checking group membership:', error)
+ return false
+ }
+ }
+
return {
user,
isAuthenticated,
logout,
goToProfile,
- checkSessionStatus
+ checkSessionStatus,
+ hasGroup,
+ checkGroupBackend
}
}
diff --git a/nuxt4/server/api/auth/check-group.post.ts b/nuxt4/server/api/auth/check-group.post.ts
new file mode 100644
index 0000000..5ac1ac4
--- /dev/null
+++ b/nuxt4/server/api/auth/check-group.post.ts
@@ -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
+ }
+})