Reset Password
better-auth-ui/reset-passwordFreeComponent
A form component for resetting password with a token from the URL.
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/reset-password.jsonSource
1"use client"23import { getAuthLinkURL } from "@better-auth-ui/core"4import { useAuth, useResetPassword } from "@better-auth-ui/react"5import { Eye, EyeOff } from "lucide-react"6import { type SyntheticEvent, useEffect, useState } from "react"7import { toast } from "sonner"89import { Button } from "@/components/ui/button"10import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"11import {12 Field,13 FieldDescription,14 FieldError,15 FieldGroup,16 FieldLabel17} from "@/components/ui/field"18import {19 InputGroup,20 InputGroupAddon,21 InputGroupButton,22 InputGroupInput23} from "@/components/ui/input-group"24import { Spinner } from "@/components/ui/spinner"25import { cn } from "@/lib/utils"2627export type ResetPasswordProps = {28 className?: string29}3031/**32 * Render a password reset form that validates the reset token from the URL, accepts a new password (and optional confirmation), and submits it to the auth client.33 *34 * The component checks for a `token` query parameter on mount and, if missing, shows an error toast and navigates to the sign-in page. It exposes per-field validation messages, toggles for password visibility, and disables inputs while the reset request is pending.35 *36 * @returns The password reset form UI ready to be mounted in the app layout.37 */38export function ResetPassword({ className }: ResetPasswordProps) {39 const {40 authClient,41 basePaths,42 emailAndPassword,43 localization,44 navigate,45 redirectTo,46 viewPaths,47 Link48 } = useAuth()49 const signInURL = getAuthLinkURL(50 `${basePaths.auth}/${viewPaths.auth.signIn}`,51 redirectTo52 )5354 const { mutate: resetPassword, isPending } = useResetPassword(authClient, {55 onSuccess: () => {56 toast.success(localization.auth.passwordResetSuccess)57 navigate({ to: signInURL })58 }59 })6061 const [isPasswordVisible, setIsPasswordVisible] = useState(false)62 const [isConfirmPasswordVisible, setIsConfirmPasswordVisible] =63 useState(false)6465 const [fieldErrors, setFieldErrors] = useState<{66 password?: string67 confirmPassword?: string68 }>({})6970 useEffect(() => {71 const searchParams = new URLSearchParams(window.location.search)72 const token = searchParams.get("token") as string7374 if (!token) {75 toast.error(localization.auth.invalidResetPasswordToken)76 navigate({ to: signInURL })77 }78 }, [localization.auth.invalidResetPasswordToken, navigate, signInURL])7980 function handleSubmit(e: SyntheticEvent<HTMLFormElement>) {81// … 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 |
