Compare commits

...

5 commits

Author SHA1 Message Date
Korbs
b31ef2b5b8 When a regular account requests delete function, direct to signout API as well 2024-07-17 19:05:49 -04:00
Korbs
281d99a4da Create API to delete anonymous accuont 2024-07-17 19:05:22 -04:00
Korbs
2078b6ed4d Show signing out warning to anonymous users 2024-07-17 19:05:09 -04:00
Korbs
a53fc0cf29 update 2024-07-17 19:04:54 -04:00
Korbs
9628d5e48e When signing out, check if user is anonymous 2024-07-17 19:04:49 -04:00
5 changed files with 43 additions and 7 deletions

View file

@ -1,4 +1,4 @@
creator,followers,id creator,followers,id
" ColdFusion",4850000,UC4QZ_LsYcvcq7qOsOhpAX4A ColdFusion,4850000,UC4QZ_LsYcvcq7qOsOhpAX4A
" Veritasium",15000000,UCHnyfMqiRRG1u-2MsSQLbXA Veritasium,15000000,UCHnyfMqiRRG1u-2MsSQLbXA
Vsause,22000000,C6nSFpj9HTCZ5t-N3Rm3-HA Vsause,22000000,C6nSFpj9HTCZ5t-N3Rm3-HA
1 creator followers id
2 ColdFusion ColdFusion 4850000 UC4QZ_LsYcvcq7qOsOhpAX4A
3 Veritasium Veritasium 15000000 UCHnyfMqiRRG1u-2MsSQLbXA
4 Vsause 22000000 C6nSFpj9HTCZ5t-N3Rm3-HA

View file

@ -0,0 +1,16 @@
---
import Base from "@layouts/Base.astro"
---
<Base Title="Supabase Demo">
<center>
<h2>End Anonymous Session</h2>
<p>You're currently in an anonymous session, these can't be logged back into. If you choose to confirm logging out, <span style="color: red">your anonymous account will be deleted immediately, this action can't be undone</span>.</p>
<p>If you're not logged into an anomymous account, try clearing your browser cookies for this website.</p>
<!-- <p>If you want to keep your anonymous account, you can convert it to a regular account, which will require setting up an email and password for it.</p> -->
<div style="display: flex; gap: 6px; justify-content: center;">
<!-- <form action="/" method="get"><button>Convert Account</button></form> -->
<form action="/api/account/anon-delete" method="post"><button>Confirm Logout</button></form>
</div>
</center>
</Base>

View file

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

View file

@ -10,5 +10,5 @@ export const POST: APIRoute = async ({ redirect }) => {
return new Response(error.message, { status: 500 }) return new Response(error.message, { status: 500 })
} }
return redirect("/signout") return redirect("/api/auth/signout")
} }

View file

@ -3,8 +3,13 @@ import { supabase } from "@library/supabase"
import type { Provider } from "@supabase/supabase-js" import type { Provider } from "@supabase/supabase-js"
export const GET: APIRoute = async ({ cookies, redirect }) => { export const GET: APIRoute = async ({ cookies, redirect }) => {
if(cookies.get('anonymous-session')) {
return redirect('/account/anon/end')
} else {
cookies.delete("sb-access-token", { path: "/" }) cookies.delete("sb-access-token", { path: "/" })
cookies.delete("sb-refresh-token", { path: "/" }) cookies.delete("sb-refresh-token", { path: "/" })
const { error } = await supabase.auth.signOut() const { error } = await supabase.auth.signOut()
return redirect("/signin") }
return redirect("/")
} }