Account deletion function
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
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.
So I should make an Edge Function that would allow users to delete their own account?
Yeah you just have to ensure via the jwt and so on that they can only delete their own account.
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
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.