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 + } +}