Forgot Password
better-auth-ui/forgot-passwordFreeComponent
A form component for requesting a password reset link via email.
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/forgot-password.jsonSource
1"use client"23import { getViewURL } from "@better-auth-ui/core"4import {5 useAuth,6 useFetchOptions,7 useRequestPasswordReset8} from "@better-auth-ui/react"9import { type SyntheticEvent, useState } from "react"1011import { Button } from "@/components/ui/button"12import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"13import {14 Field,15 FieldDescription,16 FieldError,17 FieldGroup,18 FieldLabel19} from "@/components/ui/field"20import { Input } from "@/components/ui/input"21import { Spinner } from "@/components/ui/spinner"22import { cn } from "@/lib/utils"23import { RESET_LINK_SENT_STORAGE_KEY } from "./reset-link-sent"2425export type ForgotPasswordProps = {26 className?: string27}2829/**30 * Render a card-based "Forgot Password" form that sends a password-reset email.31 *32 * The form displays an email input, submit button, and a link back to sign-in.33 * After a successful request the submitted email is stored in `sessionStorage`34 * and the user is redirected to the reset-link-sent view, which offers to open35 * their email provider.36 *37 * @param className - Optional additional CSS class names applied to the card38 * @returns The forgot-password form UI as a JSX element39 */40export function ForgotPassword({ className }: ForgotPasswordProps) {41 const {42 authClient,43 baseURL,44 basePaths,45 localization,46 navigate,47 plugins,48 viewPaths,49 Link50 } = useAuth()5152 const { fetchOptions, resetFetchOptions } = useFetchOptions()5354 const { mutate: requestPasswordReset, isPending } = useRequestPasswordReset(55 authClient,56 {57 onError: () => {58 resetFetchOptions()59 },60 onSuccess: (_data, { email }) => {61 sessionStorage.setItem(RESET_LINK_SENT_STORAGE_KEY, email)62 navigate({ to: `${basePaths.auth}/${viewPaths.auth.resetLinkSent}` })63 }64 }65 )6667 function handleSubmit(e: SyntheticEvent<HTMLFormElement>) {68 e.preventDefault()69 const formData = new FormData(e.currentTarget)70 requestPasswordReset({71 email: formData.get("email") as string,72 redirectTo: getViewURL(73 baseURL,74 basePaths.auth,75 viewPaths.auth.resetPassword76 ),77 fetchOptions78 })79 }8081 const Captcha = plugins.find(82 (plugin) => plugin.captchaComponent83 )?.captchaComponent8485 const [fieldErrors, setFieldErrors] = useState<{86 email?: string87 }>({})8889 return (90 <Card className={cn("w-full max-w-sm", className)}>91 <CardHeader>92// … 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 |
