Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabaseβ€’4y agoβ€’
6 replies
𝕓𝕖𝕕

DB Function to Insert New Users

Hello,

I would like my DB Function to make a new record in public.userProfiles when a user is added to auth.users

Here is my function and the trigger that calls it. What am I doing wrong? I've never used Postgres or SQL
create or replace function public.handle_new_user() 
returns trigger as $$
begin
  insert into public.profiles (id, email)
  values (new.id->>id, new.email->>'email');
  return new;
end;
$$ language plpgsql security definer;
create or replace function public.handle_new_user() 
returns trigger as $$
begin
  insert into public.profiles (id, email)
  values (new.id->>id, new.email->>'email');
  return new;
end;
$$ language plpgsql security definer;


and the trigger:
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();

I'm using this so that my security rules have a record to check UID against
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Insert many auth.users
SupabaseSSupabase / help-and-questions
4y ago
Where do I insert a DB function to? getting syntax errors
SupabaseSSupabase / help-and-questions
4y ago
trying to create db function which exclude non numeric values before insert&update
SupabaseSSupabase / help-and-questions
3y ago
Trigger edge function on insert
SupabaseSSupabase / help-and-questions
4y ago