import React, { useState } from "react"; import { useLocation } from "wouter"; import { supabase } from "../lib/supabase"; import { Button } from "../components/ui/button"; import { Input } from "../components/ui/input"; import { Label } from "../components/ui/label"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "../components/ui/card"; import { toast } from "sonner"; export default function ForgotPassword() { const [, setLocation] = useLocation(); const [email, setEmail] = useState(""); const [isLoading, setIsLoading] = useState(false); const [sent, setSent] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); try { const redirectTo = `${window.location.origin}${ import.meta.env.BASE_URL?.replace(/\/$/, "") ?? "" }/reset-password`; const { error } = await supabase.auth.resetPasswordForEmail(email, { redirectTo, }); if (error) { toast.error(error.message); } else { setSent(true); toast.success("Password reset link sent to your email"); } } catch { toast.error("Connection error. Please try again."); } finally { setIsLoading(false); } }; return (