"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Trash2, ArrowLeft, AlertTriangle } from "lucide-react"; import Link from "next/link"; import { useAuth } from "@/contexts/auth-context"; import { motion } from "framer-motion"; export default function DeleteAccountPage() { const [isDeleting, setIsDeleting] = useState(false); const [dialogOpen, setDialogOpen] = useState(false); const { user, isAuthenticated, loading } = useAuth(); const router = useRouter(); const handleDeleteAccount = async () => { if (!user) return; setIsDeleting(true); try { const response = await fetch('/api/user/delete', { method: 'DELETE', credentials: 'include' }); if (response.ok) { alert('Your account has been deleted. You will now be redirected to the home page. Thanks for using Kowalski!'); window.location.href = '/'; } else { const error = await response.json(); alert(`Failed to delete account: ${error.message || 'Unknown error'}`); } } catch (error) { console.error('Error deleting account:', error); alert('An error occurred while deleting your account. Please try again.'); } finally { setIsDeleting(false); setDialogOpen(false); } }; if (loading) { return (
Permanently remove your account and data
Deleting your account will permanently remove all your data, including:
This will immediately and permanently delete your account.