https://supabase.com/ logo
#help
Title
# help
j

joshcowan25

01/26/2022, 2:50 PM
How to delete a User from DB
Hi! I have a dashboard where the admin should be able to delete a user when he wants to. I tried to use trigger functions to do that, but it doesn't look like it's working.
Eveytime I delete a row in my public.profile table, it should triggers a function like that: begin DELETE FROM auth.user WHERE id = new.id; return new; end But it doesn't work!
How can I do it? I use SvelteKit on Vercel with Supabase as my DB and storage
s

silentworks

01/26/2022, 2:56 PM
You are going to need to use the deleteUser method since the
auth
schema doesn't belong to the user you are trying to do the delete with https://supabase.com/docs/reference/javascript/auth-api-deleteuser
j

joshcowan25

01/26/2022, 2:58 PM
So I can't from Postgres Functions?
s

silentworks

01/26/2022, 3:35 PM
The user that was used to create that function might not have permission to delete columns from that table
Something that looks wrong in your function above is you are using
new.id
but since it would have been deleted you probably need to use
old.id