diff --git a/components/console/account-page-client.tsx b/components/console/account-page-client.tsx index 2f577df..8d54ff2 100644 --- a/components/console/account-page-client.tsx +++ b/components/console/account-page-client.tsx @@ -2,7 +2,7 @@ import { useState } from "react"; import { Github, User, Lock, ShieldAlert, Camera, Check, Eye, EyeOff } from "lucide-react"; -import { signIn } from "next-auth/react"; +import { signIn, signOut } from "next-auth/react"; import type { UserProfile } from "@/lib/user-auth"; function Section({ title, icon, children }: { title: string; icon: React.ReactNode; children: React.ReactNode }) { @@ -42,6 +42,10 @@ export function AccountPageClient({ user, hasGithubConnection }: { user: UserPro const [deleteInput, setDeleteInput] = useState(""); const [profileSaved, setProfileSaved] = useState(false); const [pwSaved, setPwSaved] = useState(false); + + // Account destruction state handlers + const [deleting, setDeleting] = useState(false); + const [deleteError, setDeleteError] = useState(null); const saveProfile = () => { setProfileSaved(true); @@ -53,6 +57,39 @@ export function AccountPageClient({ user, hasGithubConnection }: { user: UserPro setTimeout(() => setPwSaved(false), 2000); }; + const handleDeleteAccount = async () => { + if (deleteInput !== "delete my account") return; + + // Direct user-intent safety gate validation matching Issue instructions + const doubleConfirm = window.confirm( + "CRITICAL WARNING: Are you completely sure you want to delete your account? This will instantly purge all sandboxes, deployments, security logs, and custom configuration secrets permanently." + ); + if (!doubleConfirm) return; + + setDeleting(true); + setDeleteError(null); + + try { + const res = await fetch("/api/user/account", { + method: "DELETE", + headers: { "Content-Type": "application/json" }, + }); + const data = await res.json(); + + if (res.ok && data.ok) { + alert("Your account has been successfully deleted. Goodbye!"); + // Safely wipe out NextAuth browser session states and redirect to registration index page + signOut({ callbackUrl: "/" }); + } else { + setDeleteError(data.error ?? "Failed to delete account. Please try again."); + } + } catch { + setDeleteError("Network error occurred. Unable to connect to authentication server."); + } finally { + setDeleting(false); + } + }; + return (
@@ -60,6 +97,12 @@ export function AccountPageClient({ user, hasGithubConnection }: { user: UserPro

Manage your profile and security settings

+ {deleteError && ( +
+ {deleteError} +
+ )} +
}>
{!hasGithubConnection && ( @@ -218,22 +261,24 @@ export function AccountPageClient({ user, hasGithubConnection }: { user: UserPro setDeleteInput(e.target.value)} placeholder='delete my account' className="w-full rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-900 transition-colors focus:border-red-400 focus:outline-none dark:border-zinc-700 dark:bg-zinc-800 dark:text-white" />
); -} +} \ No newline at end of file