'use client' import { useState, useEffect } 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) const [sessionReady, setSessionReady] = useState(null) useEffect(() => { const supabase = createClient() supabase.auth.getSession().then(({ data: { session } }) => { setSessionReady(!!session) }) }, []) 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) { setError('Reset link has expired. Request a new one.') return } router.push('/login?message=password_reset') } if (sessionReady === null) { return (

Loading…

) } if (!sessionReady) { return (

Reset link has expired or is invalid.

Request a new reset link
) } 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" />
) }