'use client' import * as React from 'react' import type { FieldErrors } from 'react-hook-form' import { isEmailConfigured } from '@admin/actions/profile' import { authClient } from '@admin/auth/client' import { Button } from '@admin/components/ui/button' import { Card, CardContent } from '@admin/components/ui/card' import { Field, FieldGroup, FieldLabel } from '@admin/components/ui/field' import { Form } from '@admin/components/ui/form' import { Input } from '@admin/components/ui/input' import { Spinner } from '@admin/components/ui/spinner' import { cn } from '@admin/utils/shared/cn' import { standardSchemaResolver } from '@hookform/resolvers/standard-schema' import Image from 'next/image' import Link from 'next/link' import { useForm } from 'react-hook-form' import { toast } from 'sonner' import { z } from 'zod/v3' const forgotPasswordSchema = z.object({ email: z.string().trim().min(1, 'Email is required').email('Enter a valid email address') }) type ForgotPasswordFormValues = z.infer export function ForgotPasswordForm({ className, ...props }: React.ComponentProps<'div'>) { const [isPending, startTransition] = React.useTransition() const form = useForm({ resolver: standardSchemaResolver(forgotPasswordSchema), defaultValues: { email: '' }, mode: 'onChange', reValidateMode: 'onChange' }) const handleSubmit = (values: ForgotPasswordFormValues) => { startTransition(async () => { try { const emailReady = await isEmailConfigured() if (!emailReady) { toast.error('Email delivery is not configured for this project.') return } const { error } = await authClient.requestPasswordReset({ email: values.email, redirectTo: '/admin/reset-password' }) if (error) { toast.error(error.message || 'Failed to send reset link') return } toast.success( 'If an account exists, we sent a password reset link. Check your inbox and spam folder.' ) } catch { toast.error('Failed to send the reset link. Try again.') } }) } const handleInvalid = (errors: FieldErrors) => { const message = errors.email?.message toast.error(typeof message === 'string' ? message : 'Enter a valid email address.') } return (

Forgot password

Enter your email and we'll send you a reset link when email delivery is enabled

Email Back to sign in
) }