diff --git a/apps/web/components/settings/account.tsx b/apps/web/components/settings/account.tsx index b8b51e1e..2d39fcf4 100644 --- a/apps/web/components/settings/account.tsx +++ b/apps/web/components/settings/account.tsx @@ -13,6 +13,8 @@ import { DialogClose, } from "@ui/components/dialog" import { authClient } from "@lib/auth" +import { toast } from "sonner" +import { useRouter } from "next/navigation" import { Popover, PopoverContent, PopoverTrigger } from "@ui/components/popover" import { useCustomer } from "autumn-js/react" import { @@ -89,7 +91,9 @@ function PlanFeatureRow({ export default function Account() { const { user, org, setActiveOrg } = useAuth() const autumn = useCustomer() + const router = useRouter() const [isUpgrading, setIsUpgrading] = useState(false) + const [isDeleting, setIsDeleting] = useState(false) const [deleteConfirmText, setDeleteConfirmText] = useState("") const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false) const [switchingOrgId, setSwitchingOrgId] = useState(null) @@ -142,12 +146,26 @@ export default function Account() { } } - const handleDeleteAccount = () => { + const handleDeleteAccount = async () => { if (deleteConfirmText !== "DELETE") return - // TODO: Implement account deletion API call - console.log("Delete account requested") - setIsDeleteDialogOpen(false) - setDeleteConfirmText("") + setIsDeleting(true) + + try { + const { error } = await authClient.deleteUser() + + if (error) { + throw error + } + + toast.success("Account deleted successfully") + router.push("/") + } catch (error) { + console.error("Failed to delete account:", error) + toast.error("Failed to delete account", { + description: error instanceof Error ? error.message : "Unknown error", + }) + setIsDeleting(false) + } } const isDeleteEnabled = deleteConfirmText === "DELETE" @@ -809,6 +827,7 @@ export default function Account() { > setDeleteConfirmText(e.target.value)} placeholder="DELETE" @@ -842,19 +861,23 @@ export default function Account() {