From 6a8c8a5091adef9a0d747a2e7878f4d4c844b4dd Mon Sep 17 00:00:00 2001 From: MaheshtheDev <38828053+MaheshtheDev@users.noreply.github.com> Date: Tue, 6 Jan 2026 18:39:04 +0000 Subject: feat: delete org consumer (#654) --- apps/web/components/views/profile.tsx | 117 ++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) (limited to 'apps') diff --git a/apps/web/components/views/profile.tsx b/apps/web/components/views/profile.tsx index c60f4310..62297358 100644 --- a/apps/web/components/views/profile.tsx +++ b/apps/web/components/views/profile.tsx @@ -1,12 +1,24 @@ "use client" import { useAuth } from "@lib/auth-context" +import { authClient } from "@lib/auth" import { fetchConnectionsFeature, fetchMemoriesFeature, fetchSubscriptionStatus, } from "@lib/queries" +import { + AlertDialog, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, + AlertDialogTrigger, +} from "@repo/ui/components/alert-dialog" import { Button } from "@repo/ui/components/button" +import { Input } from "@repo/ui/components/input" import { Skeleton } from "@repo/ui/components/skeleton" import { HeadingH3Bold } from "@repo/ui/text/heading/heading-h3-bold" import { useCustomer } from "autumn-js/react" @@ -20,13 +32,19 @@ import { } from "lucide-react" import { motion } from "motion/react" import Link from "next/link" +import { useRouter } from "next/navigation" import { useState } from "react" export function ProfileView() { const { user: session, org } = useAuth() const organizations = org const autumn = useCustomer() + const router = useRouter() const [isLoading, setIsLoading] = useState(false) + const [isDeleting, setIsDeleting] = useState(false) + const [deleteConfirmation, setDeleteConfirmation] = useState("") + const [deleteDialogOpen, setDeleteDialogOpen] = useState(false) + const [deleteError, setDeleteError] = useState(null) const { data: status = { @@ -74,6 +92,31 @@ export function ProfileView() { }) } + const handleDeleteAccount = async () => { + if (deleteConfirmation !== "DELETE" || !org?.id) return + + setIsDeleting(true) + setDeleteError(null) + + try { + await authClient.organization.delete({ + organizationId: org.id, + }) + + await authClient.signOut() + + router.push("/login") + } catch (error) { + console.error("Failed to delete account:", error) + setDeleteError( + error instanceof Error + ? error.message + : "Failed to delete account. Please try again or contact support.", + ) + setIsDeleting(false) + } + } + if (session?.isAnonymous) { return (
@@ -364,6 +407,80 @@ export function ProfileView() { )}
)} + + {/* Delete Account */} + {!session?.isAnonymous && org && ( +
+
+
+

Delete account

+

+ Permanently delete your data and cancel subscription +

+
+ + + + + + + Delete account? + +
+

+ This will permanently delete your memories, connections, + settings, and cancel any subscriptions. +

+

+ Type{" "} + + DELETE + {" "} + to confirm: +

+
+
+
+ setDeleteConfirmation(e.target.value)} + placeholder="DELETE" + autoComplete="off" + /> + {deleteError && ( +

{deleteError}

+ )} + + { + setDeleteConfirmation("") + setDeleteError(null) + }} + > + Cancel + + + +
+
+
+
+ )} ) } -- cgit v1.2.3