From 281d99a4da8a40a71d30b22a7d1ae4c5d4b8deaf Mon Sep 17 00:00:00 2001 From: Korbs Date: Wed, 17 Jul 2024 19:05:22 -0400 Subject: [PATCH] Create API to delete anonymous accuont --- src/pages/api/account/anon-delete.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/pages/api/account/anon-delete.ts diff --git a/src/pages/api/account/anon-delete.ts b/src/pages/api/account/anon-delete.ts new file mode 100644 index 0000000..f5be641 --- /dev/null +++ b/src/pages/api/account/anon-delete.ts @@ -0,0 +1,15 @@ +import type { APIRoute } from "astro" +import { supabase } from "@library/supabase" + +export const POST: APIRoute = async ({ cookies, redirect }) => { + + // https://supabase.com/docs/reference/javascript/auth-updateuser?example=update-the-users-metadata + const { error } = await supabase.rpc('delete_user'); + cookies.delete("anonymous-session", { path: "/" }) + + if (error) { + return new Response(error.message, { status: 500 }) + } + + return redirect("/api/auth/signout") +}