radio4000 / migrate-tool

A website for managing a Radio4000 channel migration, from firebase (realtime) to supabase
https://migrate.radio4000.com/
0 stars 0 forks source link

Can delete my user (this should cascades and deletes channel) #11

Closed oskarrough closed 3 years ago

oskarrough commented 3 years ago

... in one go I guess.

https://github.com/supabase/supabase/discussions/1066

oskarrough commented 3 years ago

Seems it's recommended to use a postgresql procedure for this. This way you avoid passing in an id and avoid row security issues (?).

CREATE or replace function delete_user()
  returns void
LANGUAGE SQL SECURITY DEFINER 
AS $$
   delete from auth.users where id = auth.uid();
$$;

Procedures can be called with supabase like this

const { data, error } = await supabase.rpc('delete_user')

See https://supabase.io/docs/reference/javascript/rpc