Add user info header to authentication dropdown
- Created /api/auth/userinfo endpoint to fetch user data from Authentik headers - Added userInfo state and fetchUserInfo() function to useAuth composable - Implemented compact user info header in dropdown with avatar, name, and email - Avatar shows user initials with gradient background - Styled with glassmorphism design matching app aesthetic
This commit is contained in:
28
server/api/auth/userinfo.get.ts
Normal file
28
server/api/auth/userinfo.get.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
export default defineEventHandler((event) => {
|
||||
// Authentik forward-auth pasa información del usuario en headers
|
||||
const username = getHeader(event, 'x-authentik-username') || 'Usuario'
|
||||
const email = getHeader(event, 'x-authentik-email') || ''
|
||||
const name = getHeader(event, 'x-authentik-name') || ''
|
||||
const uid = getHeader(event, 'x-authentik-uid') || ''
|
||||
|
||||
// Retornar información del usuario
|
||||
return {
|
||||
username,
|
||||
email,
|
||||
name: name || username, // Usar username si no hay name
|
||||
uid,
|
||||
initials: getInitials(name || username)
|
||||
}
|
||||
})
|
||||
|
||||
// Helper para obtener iniciales
|
||||
function getInitials(name: string): string {
|
||||
if (!name) return '?'
|
||||
|
||||
const parts = name.trim().split(/\s+/)
|
||||
if (parts.length === 1) {
|
||||
return parts[0].substring(0, 2).toUpperCase()
|
||||
}
|
||||
|
||||
return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase()
|
||||
}
|
||||
Reference in New Issue
Block a user