© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
2 replies
lake_mattiato

How to create a new row in public.users_data when a new user is added to auth.User

So i have the following table
users_data (pk: email: text, first_name: text, last_name: text, phone_number: text, area_of_speciality: text, user_type: text, fk: organisation_id: int, created_at: timestamp, first_login: bool)
users_data (pk: email: text, first_name: text, last_name: text, phone_number: text, area_of_speciality: text, user_type: text, fk: organisation_id: int, created_at: timestamp, first_login: bool)

All values are allowed to be nullable except for the primary key. First_login field sets the default value to true.

So what is the best way to create a trigger that inserts the the email from auth.Users to public.users_data

I already tried this method
/**
* 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_data (email)
  values (new.email);
  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();
/**
* 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_data (email)
  values (new.email);
  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();


but when i try to sign up via postman i get this response:
{"code":"23502","message":"null value in column \"email\" of relation \"users_data\" violates not-null constraint","detail":"Failing row contains (null, null, null, null, null, null, null, null, null, 2022-12-09 08:55:45.605194+00, f)."}%
{"code":"23502","message":"null value in column \"email\" of relation \"users_data\" violates not-null constraint","detail":"Failing row contains (null, null, null, null, null, null, null, null, null, 2022-12-09 08:55:45.605194+00, f)."}%
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

Sending an email with row data when new row is added
SupabaseSSupabase / help-and-questions
4y ago
Cannot create public.users
SupabaseSSupabase / help-and-questions
3y ago
User role stored in public.users or raw_user_meta_data?
SupabaseSSupabase / help-and-questions
3y ago
Error when trying to create a new user
SupabaseSSupabase / help-and-questions
13mo ago