Skip to content

Commit

Permalink
feat: use supabase admin client
Browse files Browse the repository at this point in the history
  • Loading branch information
Balastrong committed Sep 14, 2024
1 parent 998769a commit 1a58b59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/components/ProfileDeleteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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!`)
Expand Down
17 changes: 7 additions & 10 deletions src/services/settings/api.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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("/")
}

0 comments on commit 1a58b59

Please sign in to comment.