Skip to content

Instantly share code, notes, and snippets.

@jasonho-lynx
Created September 3, 2021 10:28
Show Gist options
  • Save jasonho-lynx/e13b15304b41a2674b797811efcd1df1 to your computer and use it in GitHub Desktop.
Save jasonho-lynx/e13b15304b41a2674b797811efcd1df1 to your computer and use it in GitHub Desktop.
-- trigger function is created here (not the actual trigger).
CREATE OR REPLACE FUNCTION insert_into_public_users()
RETURNS TRIGGER AS $$
BEGIN
INSERT INTO public.users (id, email, created_at)
VALUES(NEW.id, NEW.email, NOW());
RETURN NEW;
END;
$$
LANGUAGE plpgsql SECURITY DEFINER;
-- defining a trigger on the auth.users table.
-- calls the insert_into_public_users() trigger function for every row that is inserted into auth.users.
CREATE TRIGGER on_signup
AFTER INSERT ON auth.users
FOR EACH ROW EXECUTE PROCEDURE insert_into_public_users();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment