import { useState, useEffect } from 'react'; import { supabase } from '../lib/supabaseClient'; export function ResetPassword() { const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [message, setMessage] = useState(null); const [error, setError] = useState(null); useEffect(() => { // Handle hash fragment if present (implicit flow) const hash = window.location.hash; if (hash && hash.includes('type=recovery')) { // Supabase handles the session automatically if the link is clicked // We just need to let the user set a new password } }, []); const handlePasswordReset = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(null); setMessage(null); try { const { error } = await supabase.auth.updateUser({ password }); if (error) throw error; setMessage('Password updated successfully! You can now login.'); setTimeout(() => { if (typeof window !== 'undefined') { window.location.href = '/'; } }, 2000); } catch (err: any) { setError(err.message); } finally { setLoading(false); } }; return (

Reset Password

Enter your new password below

setPassword(e.target.value)} placeholder="New password" required />
{error &&
{error}
} {message &&
{message}
}
); }