User Profile
better-auth-ui/user-profileFreeComponent
A form component for editing user profile information including name and avatar.
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-profile.jsonSource
1"use client"23import {4 type AdditionalFieldValue,5 parseAdditionalFieldValue6} from "@better-auth-ui/core"7import {8 type UsernameAuthClient,9 useAuth,10 useSession,11 useUpdateUser12} from "@better-auth-ui/react"13import { type SyntheticEvent, useState } from "react"14import { toast } from "sonner"1516import { Button } from "@/components/ui/button"17import { Card, CardContent, CardFooter } from "@/components/ui/card"18import { Field, FieldError, FieldLabel } from "@/components/ui/field"19import { Input } from "@/components/ui/input"20import { Skeleton } from "@/components/ui/skeleton"21import { Spinner } from "@/components/ui/spinner"22import { cn } from "@/lib/utils"23import { AdditionalField } from "../../additional-field"24import { ChangeAvatar } from "./change-avatar"2526export type UserProfileProps = {27 className?: string28}2930/**31 * Render a profile card that lets the authenticated user view and update their display name, username, and avatar.32 *33 * @param className - Optional additional CSS class names applied to the card container34 * @returns A JSX element containing the profile card with avatar upload and editable name/username fields35 */36export function UserProfile({ className }: UserProfileProps) {37 const { additionalFields, authClient, localization } = useAuth()38 const { data: session } = useSession(authClient as UsernameAuthClient)3940 const { mutate: updateUser, isPending } = useUpdateUser(authClient, {41 onSuccess: () => toast.success(localization.settings.profileUpdatedSuccess)42 })4344 const [fieldErrors, setFieldErrors] = useState<{45 name?: string46 }>({})4748 async function handleSubmit(e: SyntheticEvent<HTMLFormElement>) {49 e.preventDefault()5051 const formData = new FormData(e.currentTarget)52 const name = formData.get("name") as string5354 const additionalFieldValues: Record<string, unknown> = {}5556 for (const field of additionalFields ?? []) {57 if (field.profile === false || field.readOnly) continue58 const value = parseAdditionalFieldValue(59 field,60 formData.get(field.name) as string | null61 )6263 if (field.validate) {64 try {65 await field.validate(value)66 } catch (error) {67 toast.error(error instanceof Error ? error.message : String(error))68 return69 }70 }7172 // `null` = explicit clear (forward to backend); `undefined` = omitted.73 if (value !== undefined) {74 additionalFieldValues[field.name] = value75 }76 }7778 updateUser({79// … 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 |
