'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import { updatePassword } from '@/lib/actions/auth' import { cn } from '@/lib/utils/index' import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' export function UpdatePasswordForm({ className, token, ...props }: React.ComponentPropsWithoutRef<'div'> & { token?: string }) { const [password, setPassword] = useState('') const [error, setError] = useState(null) const [isLoading, setIsLoading] = useState(false) const router = useRouter() const handleForgotPassword = async (e: React.FormEvent) => { e.preventDefault() setIsLoading(true) setError(null) try { const result = await updatePassword(password, token) if (!result.success) throw new Error(result.error ?? 'An error occurred') // Redirect to root and refresh to ensure server components get updated session. // A token reset (better-auth) establishes no session: the provider // redirects to the sign-in page instead. router.push(result.redirectTo ?? '/') router.refresh() } catch (error: unknown) { setError(error instanceof Error ? error.message : 'An error occurred') } finally { setIsLoading(false) } } return (
Reset Your Password Please enter your new password below.
setPassword(e.target.value)} />
{error &&

{error}

}
) }