From 7de670d8247fe53c001cd8bc8d195866231d4895 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Sun, 12 Oct 2025 22:53:44 -0600 Subject: [PATCH] Add Authentik integration UI components - Create useAuthentik composable to read headers - Add UserAvatar component with avatar and user info - Add StatusBadges for auth/connection status - Add ActionButtons for logout and profile - Add UserMetadata component with full user details - Integrate all components in main page - Use Nuxt UI components throughout --- nuxt4/app/app.vue | 53 +++++++++++++++++- nuxt4/components/auth/ActionButtons.vue | 34 ++++++++++++ nuxt4/components/auth/StatusBadges.vue | 46 ++++++++++++++++ nuxt4/components/auth/UserAvatar.vue | 20 +++++++ nuxt4/components/auth/UserMetadata.vue | 73 +++++++++++++++++++++++++ nuxt4/composables/useAuthentik.ts | 51 +++++++++++++++++ 6 files changed, 274 insertions(+), 3 deletions(-) create mode 100644 nuxt4/components/auth/ActionButtons.vue create mode 100644 nuxt4/components/auth/StatusBadges.vue create mode 100644 nuxt4/components/auth/UserAvatar.vue create mode 100644 nuxt4/components/auth/UserMetadata.vue create mode 100644 nuxt4/composables/useAuthentik.ts diff --git a/nuxt4/app/app.vue b/nuxt4/app/app.vue index 09f935b..904688b 100644 --- a/nuxt4/app/app.vue +++ b/nuxt4/app/app.vue @@ -1,6 +1,53 @@ + + diff --git a/nuxt4/components/auth/ActionButtons.vue b/nuxt4/components/auth/ActionButtons.vue new file mode 100644 index 0000000..db99b40 --- /dev/null +++ b/nuxt4/components/auth/ActionButtons.vue @@ -0,0 +1,34 @@ + + + diff --git a/nuxt4/components/auth/StatusBadges.vue b/nuxt4/components/auth/StatusBadges.vue new file mode 100644 index 0000000..b99eee5 --- /dev/null +++ b/nuxt4/components/auth/StatusBadges.vue @@ -0,0 +1,46 @@ + + + diff --git a/nuxt4/components/auth/UserAvatar.vue b/nuxt4/components/auth/UserAvatar.vue new file mode 100644 index 0000000..c11c039 --- /dev/null +++ b/nuxt4/components/auth/UserAvatar.vue @@ -0,0 +1,20 @@ + + + diff --git a/nuxt4/components/auth/UserMetadata.vue b/nuxt4/components/auth/UserMetadata.vue new file mode 100644 index 0000000..2d53897 --- /dev/null +++ b/nuxt4/components/auth/UserMetadata.vue @@ -0,0 +1,73 @@ + + + diff --git a/nuxt4/composables/useAuthentik.ts b/nuxt4/composables/useAuthentik.ts new file mode 100644 index 0000000..cd41ea3 --- /dev/null +++ b/nuxt4/composables/useAuthentik.ts @@ -0,0 +1,51 @@ +/** + * Composable para leer información de usuario de Authentik + * Los headers son inyectados por Authentik Proxy Outpost + */ +export const useAuthentik = () => { + const headers = useRequestHeaders() + + const user = computed(() => { + const username = headers['x-authentik-username'] + const email = headers['x-authentik-email'] + const name = headers['x-authentik-name'] + const groups = headers['x-authentik-groups'] + const uid = headers['x-authentik-uid'] + + // Si no hay username, el usuario no está autenticado + if (!username) { + return null + } + + return { + username, + email, + name, + groups: groups ? groups.split('|') : [], + uid, + // Generar avatar URL usando UI Avatars + avatar: `https://ui-avatars.com/api/?name=${encodeURIComponent(name || username)}&background=random&size=128` + } + }) + + const isAuthenticated = computed(() => !!user.value) + + const logout = () => { + // Authentik Proxy Outpost maneja el logout + // Redirigir a /outpost.goauthentik.io/sign_out + navigateTo('/outpost.goauthentik.io/sign_out', { external: true }) + } + + const goToProfile = () => { + // URL de perfil de Authentik + const authentikUrl = useRuntimeConfig().public.authentikUrl || 'https://authentik.nucleoriofrio.com' + navigateTo(`${authentikUrl}/if/user/`, { external: true, open: { target: '_blank' } }) + } + + return { + user, + isAuthenticated, + logout, + goToProfile + } +}