supabase delete user through application #12170
-
I have a supabase project where I want the users to be able to delete their account. So I created this: CREATE OR REPLACE FUNCTION deleteUser() RETURNS TRIGGER AS $$
BEGIN
DELETE FROM auth.users WHERE auth.users.id = OLD.user_id;
RETURN OLD;
END $$ LANGUAGE 'plpgsql';
CREATE TRIGGER deleteUserTrigger
AFTER DELETE
ON public.profiles
FOR EACH ROW
EXECUTE PROCEDURE deleteUser(); In the supabase table-editor interface it works great, but when I delete an account through my application it fails with: const { error } = await client.from("profiles").delete().eq("user_id", user.id);
console.log(error) Without the trigger there is no error and the profile is deleted (but the account persists obviously). Any help would be much appreciated! I found this but I doesn't help me |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You would need to make your trigger function "security definer" type to access the users table.
|
Beta Was this translation helpful? Give feedback.
You would need to make your trigger function "security definer" type to access the users table.
END $$ LANGUAGE 'plpgsql' security definer;