"use client"; import { useState, type CSSProperties, type FC, type ReactNode } from "react"; import { AuthCard, ResetPasswordForm, type ResetPasswordValues } from "@crema/auth-ui"; import { ArcadiaError, useArcadiaClient } from "@crema/arcadia-client"; export interface PasswordResetConfirmFormProps { /** Token from the reset email URL. */ token: string; /** Where to POST. Defaults to "/api/v1/password-reset/confirm". */ confirmPath?: string; onSuccess: () => void | Promise; brand?: ReactNode; heading?: string; subhead?: ReactNode; style?: CSSProperties; } export const PasswordResetConfirmForm: FC = ({ token, confirmPath = "/api/v1/password-reset/confirm", onSuccess, brand, heading = "Set a new password", subhead, style, }) => { const arcadia = useArcadiaClient(); const [error, setError] = useState(null); async function handleSubmit({ password }: ResetPasswordValues) { setError(null); try { await arcadia.POST(confirmPath, { body: { token, password } }); await onSuccess(); } catch (err) { if (err instanceof ArcadiaError) setError(err.message); else setError("Something went wrong. Please try again."); throw err; } } return (
{error ? (
{error}
) : null}
); };