delete a user #35987
-
I am looking into the best way to delete a user. I have a swift Mobile IOS app and the user should be able to remove its account.I understand that the deleteuser function must be executed using the service_role key. I already have a look at this discussion https://github.com/orgs/supabase/discussions/21274 My idea would be that the user sets a delete flag in its public.user_profile row when hitting the delete account button in the IOS App. The user_profile table is using RLS so the user can only update its own user_profile row in the table. The update would have a trigger linked to a postgres function that delete the user from the auth.users table. Because I have cascade delete on the public.user_profile table, the related row will also be removed. Is it is safe to directly delete from the auth.users table using a SQL query ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Yes you can delete the auth.users row directly and it will drop other rows in auth as needed. |
Beta Was this translation helpful? Give feedback.
-
That function should then have SECURITY DEFINER instead of SECURITY INVOKER. Correct ? |
Beta Was this translation helpful? Give feedback.
Yes you can delete the auth.users row directly and it will drop other rows in auth as needed.
You could also do this with an rpc call to a postgres function and use auth.uid() to do that SQL delete.