Skip to content

Sign-up database trigger to insert into public users table #306

Answered by kiwicopple
skoshy asked this question in Questions
Discussion options

You must be logged in to vote

I suspect it's permissions - the trigger is probably getting called by the anon user. You can try to add security definer to the function, which will use the same permissions as the user who created the function.

Here is a snippet that should work:

/**
* This trigger automatically creates a user entry when a new user signs up via Supabase Auth.
*/ 
create function public.handle_new_user() 
returns trigger as $$
begin
  insert into public.users (id)
  values (new.id);
  return new;
end;
$$ language plpgsql security definer;
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();

Replies: 6 comments 53 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
28 replies
@activenode
Comment options

@kiwimagic
Comment options

@DongHY1
Comment options

@davidpedrero
Comment options

@teamclouday
Comment options

Answer selected by skoshy
Comment options

You must be logged in to vote
15 replies
@inian
Comment options

@user72356
Comment options

@GaryAustin1
Comment options

@user72356
Comment options

@GaryAustin1
Comment options

Comment options

You must be logged in to vote
3 replies
@activenode
Comment options

@TStone45
Comment options

@activenode
Comment options

Comment options

You must be logged in to vote
7 replies
@GaryAustin1
Comment options

@TStone45
Comment options

@GaryAustin1
Comment options

@TStone45
Comment options

@GaryAustin1
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet