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") +}