Change Password
better-auth-ui/change-passwordFreeComponent
A form component for users to change their password with current password verification.
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/change-password.jsonSource
1"use client"23import { getViewURL } from "@better-auth-ui/core"4import {5 useAuth,6 useChangePassword,7 useFetchOptions,8 useListAccounts,9 useRequestPasswordReset,10 useSession11} from "@better-auth-ui/react"12import { Eye, EyeOff } from "lucide-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 {21 InputGroup,22 InputGroupAddon,23 InputGroupButton,24 InputGroupInput25} from "@/components/ui/input-group"26import { Skeleton } from "@/components/ui/skeleton"27import { Spinner } from "@/components/ui/spinner"28import { cn } from "@/lib/utils"29import { OpenEmailButton } from "../../open-email-button"3031export type ChangePasswordProps = {32 className?: string33}3435/**36 * Render a card form for changing the authenticated user's password.37 *38 * When the user has a credential account, displays fields for current password,39 * new password, and optionally confirm password. When the user only has social40 * accounts, displays a prompt to set a password via the reset flow.41 *42 * @returns A JSX element containing the change-password or set-password card43 */44export function ChangePassword({ className }: ChangePasswordProps) {45 const { authClient, emailAndPassword, localization } = useAuth()46 const { data: session } = useSession(authClient)47 const { data: accounts, isPending: isAccountsPending } =48 useListAccounts(authClient)4950 const hasCredentialAccount = accounts?.some(51 (account) => account.providerId === "credential"52 )5354 if (!isAccountsPending && !hasCredentialAccount) {55 return <SetPassword className={className} />56 }5758 return (59 <ChangePasswordForm60 className={className}61 emailAndPassword={emailAndPassword}62 localization={localization}63 session={isAccountsPending ? undefined : session}64 />65 )66}6768function SetPassword({ className }: { className?: string }) {69 const { authClient, basePaths, baseURL, localization, plugins, viewPaths } =70 useAuth()71 const { data: session } = useSession(authClient)72 const { fetchOptions, resetFetchOptions } = useFetchOptions()73 const [sentEmail, setSentEmail] = useState("")7475 const { mutate: requestPasswordReset, isPending } = useRequestPasswordReset(76 authClient,77 {78 onError: () => {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 |
