"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 (
); } if (!isAuthenticated) { router.push('/login'); return null; } return (

Delete Account

Permanently remove your account and data

This action cannot be undone

Deleting your account will permanently remove all your data, including:

  • Your user profile and settings
  • AI usage statistics and request history
  • Custom AI model preferences
  • Command configuration and disabled commands
  • All associated sessions and authentication data

Account Information

Username: @{user?.username}
Name: {user?.firstName} {user?.lastName}
Telegram ID: {user?.telegramId}
AI Requests: {user?.aiRequests.toLocaleString()}

Ready to delete your account?

This will immediately and permanently delete your account.

Confirm Account Deletion

Are you absolutely sure you want to delete your account? This action cannot be undone.

Your account @{user?.username} and all associated data will be permanently removed.

); }