"use client"; import { useState, type CSSProperties, type FC, type ReactNode } from "react"; import { AuthCard, ForgotPasswordForm } from "@crema/auth-ui"; import { ArcadiaError, useArcadiaClient } from "@crema/arcadia-core-client"; export interface PasswordResetRequestFormProps { /** Where to POST. Defaults to "/api/v1/password-reset/request". */ requestPath?: string; onSuccess?: (email: string) => void | Promise; onBack?: () => void; brand?: ReactNode; heading?: string; subhead?: ReactNode; style?: CSSProperties; } export const PasswordResetRequestForm: FC = ({ requestPath = "/api/v1/password-reset/request", onSuccess, onBack, brand, heading = "Reset your password", subhead = "Enter the email associated with your account and we'll send you a reset link.", style, }) => { const arcadia = useArcadiaClient(); const [sentTo, setSentTo] = useState(null); const [error, setError] = useState(null); async function handleSubmit(email: string) { setError(null); try { await arcadia.POST(requestPath, { body: { email } }); setSentTo(email); await onSuccess?.(email); } catch (err) { // Most deployments respond 200 even for unknown emails (anti-enumeration). // We only land here on hard failures (rate limit, validation, server). if (err instanceof ArcadiaError) setError(err.message); else setError("Something went wrong. Please try again."); throw err; } } return ( Back to sign in ) : undefined } >
{sentTo ? (
If an account exists for {sentTo}, we've sent a reset link.
) : ( )} {error ? (
{error}
) : null}
); };