1. Create the Trigger Function:
This function grabs the newly created user's ID and (optionally) email from the auth.users
table during signup. You can then use this information to populate another table, like user_profiles
.
CREATE OR REPLACE FUNCTION public.create_new_user_profile()
RETURNS trigger AS $$
BEGIN
INSERT INTO public.users (id, email)
VALUES (NEW.id, NEW.email);
RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
2. Set Up the Trigger:
This code tells the database to run the create_new_user_profile
function whenever a new user is inserted into the auth.users
table.
CREATE TRIGGER on_auth_user_created
AFTER INSERT ON auth.users
FOR EACH ROW
EXECUTE PROCEDURE public.create_new_user_profile();
Benefits:
Remember:
By following these steps, you can leverage SQL triggers in Supabase to streamline user data management and enhance your application's signup flow.
Catch Typos Early with crate-ci/typos
Typos can creep into any codebase, but they don't have to slow you down. crate-ci/typos is a handy tool that helps you identify and fix typos in your project.
Còn chút gì để nhớ
Bài cảm nhận tham gia cuộc thi "Trở lại học trò" do Nhà xuất bản Trẻ tổ chức nhân sự kiện ra mắt truyện dài "Lá nằm trong lá" 2011