Created
September 10, 2024 13:26
-
-
Save Sama-004/78ef676029b16031e995c1e78c7dfcf4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- inserts a row into public.user_profiles with only id and user_id | |
create or replace function public.handle_new_user() | |
returns trigger | |
language plpgsql | |
security definer set search_path = '' | |
as $$ | |
begin | |
insert into public.user_profiles (id, user_id, username) | |
VALUES (new.id, new.id, (new.raw_user_meta_data->>'username')); | |
return new; | |
end; | |
$$; | |
-- trigger the function every time a user is created | |
drop trigger if exists on_auth_user_created on auth.users; | |
create trigger on_auth_user_created | |
after insert on auth.users | |
for each row execute procedure public.handle_new_user(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment