supabase-flutter icon indicating copy to clipboard operation
supabase-flutter copied to clipboard

Account deletion function

Open erkinovalim opened this issue 1 year ago • 4 comments

There is no function for the users to delete their own account.

I would like a simple function that would allow users to delete their own account like: Supabase.auth.deleteAccount( email: [email protected] password: 123456 )

Alternative: Maybe delete the user's row from the 'users' table then delete the account from 'auth.users' table manually? But this would be slow and you would have to manually search for accounts that don't have a row in 'users' table

erkinovalim avatar Sep 17 '24 13:09 erkinovalim

Deleting users requires the service_role key. This is also true for deleting your own account. The method to delete users in dart already exists, but you probably want to delete a user from an edge function to not expose your service_role key.

Vinzent03 avatar Sep 17 '24 14:09 Vinzent03

So I should make an Edge Function that would allow users to delete their own account?

erkinovalim avatar Sep 17 '24 14:09 erkinovalim

Yeah you just have to ensure via the jwt and so on that they can only delete their own account.

Vinzent03 avatar Sep 17 '24 14:09 Vinzent03

I am a beginner and I don't really understand backend stuff. Could you explain how to use that please? I would appreciate if you could write the edge function code

erkinovalim avatar Sep 17 '24 14:09 erkinovalim

I've created a Postgres rpc function with security definer called delete_account.

Inside I grab the jwt of the caller and then delete the calling user's account.

DanMossa avatar Oct 09 '24 18:10 DanMossa