User Button
better-auth-ui/user-buttonFreeComponent
Renders a user button with dropdown menu showing user info, settings link, plugin-contributed menu items (e.g. theme toggle, account switcher), and sign-in/sign-out actions.
Live preview
live · rendered by the registry
Rendered by better-auth-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://better-auth-ui.com/r/user-button.jsonSource
1"use client"23import {4 type MultiSessionAuthClient,5 useAuth,6 useSession,7 useSetActiveSession8} from "@better-auth-ui/react"9import {10 ChevronsUpDown,11 LogIn,12 LogOut,13 Settings,14 UserPlus215} from "lucide-react"16import { isValidElement, type ReactElement, type ReactNode } from "react"1718import { buttonVariants } from "@/components/ui/button"19import {20 DropdownMenu,21 DropdownMenuContent,22 DropdownMenuGroup,23 DropdownMenuItem,24 DropdownMenuLabel,25 DropdownMenuSeparator,26 DropdownMenuTrigger27} from "@/components/ui/dropdown-menu"28import { cn } from "@/lib/utils"29import { UserAvatar } from "./user-avatar"30import { UserView } from "./user-view"3132/** Auth states a `UserButton` link can be visible in. */33export type UserButtonLinkVisibility =34 | "authenticated"35 | "unauthenticated"36 | "always"3738/** A simple link entry rendered as a `DropdownMenuItem` in the `UserButton` menu. */39export type UserButtonLink = {40 /** Visible label. */41 label: ReactNode42 /** Destination URL. */43 href: string44 /** Optional leading icon. Sized/coloured to match built-in items. */45 icon?: ReactNode46 /** Forwarded to the underlying `DropdownMenuItem`. */47 variant?: "default" | "destructive"48 /**49 * When this link is visible based on auth state.50 * @default "always"51 */52 visibility?: UserButtonLinkVisibility53}5455export type UserButtonProps = {56 className?: string57 align?: "center" | "end" | "start" | undefined58 sideOffset?: number59 size?: "default" | "icon"60 variant?:61 | "default"62 | "destructive"63 | "ghost"64 | "link"65 | "outline"66 | "secondary"67 /** Additional menu entries rendered above the built-in items. */68 links?: (UserButtonLink | ReactElement)[]69 /** Hide the built-in "Settings" link. Useful when replacing it via `links`. */70 hideSettings?: boolean71}7273function renderUserLink(74 link: UserButtonLink | ReactElement,75 navigate: (options: { to: string; replace?: boolean }) => void,76 fallbackKey: string77): ReactNode {78 if (isValidElement(link)) return link7980 const { label, href, icon, variant } = link81 return (82 <DropdownMenuItem83 key={fallbackKey}84 variant={variant}85 onClick={() => navigate({ to: href })}86 >87 {icon}88 {label}89 </DropdownMenuItem>90 )91}9293/**94 * Render a user dropdown button that shows user info, settings, theme controls, and authentication actions.95 *96 * Includes user profile, settings link, optional multi-session account switching, theme picker,97// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from better-auth-ui
All 49 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Account Settingsaccount-settings | better-auth-ui | Components | Free | 2 deps | |
| Active Sessionsactive-sessions | better-auth-ui | Components | Free | 5 deps · 2 files | |
| Additional Fieldadditional-field | better-auth-ui | Components | Free | 5 deps | |
| Adminadmin | better-auth-ui | Components | Free | 4 deps · 3 files | |
| Anonymousanonymous | better-auth-ui | Components | Free | 4 deps · 3 files | |
| API Keyapi-key | better-auth-ui | Components | Free | 4 deps · 10 files | |
| Authauth | better-auth-ui | Components | Free | 2 deps | |
| Auth Providerauth-provider | better-auth-ui | Components | Free | 4 deps · 2 files |
