diff --git a/src/components/ProfileDeleteDialog.tsx b/src/components/ProfileDeleteDialog.tsx index ae8c5a0..5a37f66 100644 --- a/src/components/ProfileDeleteDialog.tsx +++ b/src/components/ProfileDeleteDialog.tsx @@ -45,12 +45,12 @@ export function ProfileDeleteDialog({ const isDesktop = useMediaQuery("(min-width: 640px)") const DRAWER_TITLE = "Are you absolutely sure?" const DRAWER_DESCRIPTION = - "This action cannot be undone. It will permanently delete your account from your Myntenance. This action will not affect your GitHub repository." + "This action cannot be undone. It will permanently delete your account from your Myntenance. This action will not affect any of your GitHub repositories." function onDelete() { startDeleteTransition(async () => { try { - const res = await deleteOwnAccount() + await deleteOwnAccount() router.push("/") onSuccess?.() toast.success(`Your account was successfully deleted!`) diff --git a/src/services/settings/api.ts b/src/services/settings/api.ts index ae61b92..bb62756 100644 --- a/src/services/settings/api.ts +++ b/src/services/settings/api.ts @@ -1,5 +1,6 @@ "use server" import { createClient } from "@/lib/supabase/server" +import { createAdminClient } from "@/lib/supabase/serverAdmin" import { ProfileUpdate, SettingsUpdate } from "@/lib/supabase/types" import { getCurrentUserId } from "@/lib/supabase/utils" import { revalidatePath } from "next/cache" @@ -40,20 +41,16 @@ export async function updateOwnSettings( return { error: profileError } } -// TODO Set right parameters for the delete export async function deleteOwnAccount() { const supabase = createClient() const userId = await getCurrentUserId(supabase) - const result = await supabase - .from("user_profiles") - .delete() - .eq("id", userId!) - .select() - .single() - .throwOnError() + if (!userId) { + throw new Error("User not found") + } + + await createAdminClient().auth.admin.deleteUser(userId) await supabase.auth.signOut() - revalidatePath("/") - return result + revalidatePath("/") }