import * as React from "react"; import { useLocation } from "react-router-dom"; import { toast } from "@/components/ui/use-toast"; import SEO from "@/components/SEO"; const FinalizeAccountDeletion: React.FC = () => { const location = useLocation(); const [userId, setUserId] = React.useState(null); const [loading, setLoading] = React.useState(false); React.useEffect(() => { const qp = new URLSearchParams(location.search); const id = qp.get("user_id") || qp.get("userId"); if (id) setUserId(id); }, [location.search]); const onDelete = async () => { if (!userId) { toast({ title: "Missing user id in the URL." }); return; } setLoading(true); try { const envBase = (import.meta as any).env?.VITE_API_URL as string | undefined; const base = envBase ? envBase.replace(/\/$/, "") : "http://localhost:8080"; const url = `${base}/account/me?user_id=${encodeURIComponent(userId)}`; const res = await fetch(url, { method: "DELETE" }); if (!res.ok) { const text = await res.text().catch(() => ""); throw new Error(text || `Status ${res.status}`); } toast({ title: "Account deleted", description: "Your account has been removed." }); setTimeout(() => { window.location.href = "/"; }, 700); } catch (err: any) { toast({ title: "Error", description: err?.message ?? String(err) }); } finally { setLoading(false); } }; return (

Finalize account deletion

TailTrails Logo
TailTrails
This action will permanently delete your account
{userId ? (
) : (

Invalid or expired deletion link.

)}
); }; export default FinalizeAccountDeletion;