/* UserMenu — top-bar dropdown anchored to the signed-in user. * * Shows the user's name, email, and role pill at the top, then offers * shortcuts to /settings and /settings/security, and a sign-out action * that bounces back to /auth/sign-in. */ 'use client'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { useSession, signOut } from '@/lib/auth-client'; import { LogOut, User as UserIcon, ShieldCheck, Settings } from 'lucide-react'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { StatusBadge } from '@/components/ui/status-badge'; import { Button } from '@/components/ui/button'; export function UserMenu() { const { data: session } = useSession(); const router = useRouter(); const user = session?.user as | { name?: string; email?: string; role?: string } | undefined; if (!user) return null; const initials = (user.name ?? user.email ?? '?') .split(/[\s@]/) .filter(Boolean) .slice(0, 2) .map((p) => p[0]?.toUpperCase()) .join(''); const role = user.role ?? 'user'; const roleTone = role === 'super-admin' ? 'accent' : role === 'admin' ? 'info' : 'neutral'; const roleLabel = role === 'super-admin' ? 'Super-admin' : role === 'admin' ? 'Admin' : 'User'; async function handleSignOut() { await signOut(); router.push('/auth/sign-in'); } return (
{user.name && {user.name}} {user.email && ( {user.email} )} {roleLabel}
Settings Security Sign out
); }