'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import Link from 'next/link' import { createClient } from '@/lib/supabase/client' export default function ResetPasswordPage() { const router = useRouter() const [password, setPassword] = useState('') const [confirm, setConfirm] = useState('') const [loading, setLoading] = useState(false) const [error, setError] = useState(null) async function handleSubmit(e: React.FormEvent) { e.preventDefault() setError(null) if (password.length < 8) { setError('Password must be at least 8 characters.') return } if (password !== confirm) { setError('Passwords do not match.') return } setLoading(true) const supabase = createClient() const { error: updateError } = await supabase.auth.updateUser({ password }) setLoading(false) if (updateError) { if ( updateError.message.toLowerCase().includes('session') || updateError.message.toLowerCase().includes('expired') ) { setError('Reset link has expired. Request a new one.') } else { setError(updateError.message) } return } router.push('/login?message=password_reset') } return (

Set new password

Choose a strong password.

{error && (

{error}{' '} {error.includes('expired') && ( Request new link )}

)} setPassword(e.target.value)} required minLength={8} autoComplete="new-password" className="border border-gray-300 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" /> setConfirm(e.target.value)} required autoComplete="new-password" className="border border-gray-300 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" />
) }