Fix guides / Supabase: "Database error saving new user"

How to fix "Database error saving new user" in Supabase

New users cannot sign up. The app shows Database error saving new user, or AuthApiError with status 500. Supabase Auth is fine; something that runs when a user row is created is failing and cancelling the whole signup.

What is really failing

Most AI-built apps add a trigger on auth.users that creates a matching row in public.profiles whenever someone signs up. If that trigger function errors for any reason, Postgres rolls back the signup and Auth reports this generic message.

Step 1: read the real error

Supabase dashboard, Logs, then Postgres (or Auth). Look around the time of a failed signup. Common messages:

  • relation "profiles" does not exist: the table is missing or named differently.
  • permission denied for table profiles: the function runs without enough privileges.
  • null value in column "username" violates not-null constraint: the trigger does not supply a required column.
  • duplicate key value violates unique constraint: the profile row already exists, or a unique column clashes.

Step 2: recreate the function correctly

Supabase Auth inserts users as a limited role. A trigger function that writes to your tables must be security definer (runs with the owner's rights), with a pinned search_path and fully qualified table names:

create or replace function public.handle_new_user()
returns trigger
language plpgsql
security definer
set search_path = ''
as $$
begin
  insert into public.profiles (id, full_name, avatar_url)
  values (
    new.id,
    new.raw_user_meta_data ->> 'full_name',
    new.raw_user_meta_data ->> 'avatar_url'
  );
  return new;
end;
$$;

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();

Adjust the column list to match your profiles table. Every not null column without a default must get a value here.

Step 3: make the table forgiving

  • Give optional columns defaults or allow nulls. Signup metadata like full_name is often missing for email signups.
  • If a unique username is required, generate one in the trigger or let users choose it after signup.

How to verify

Sign up with a new email in a private window, then check that both the user (Authentication, Users) and the profile row exist.

Still stuck? No shame in it: these bugs hide in settings your AI builder cannot see. Send us the error and your repo and we will fix it as a pull request within 24 hours, explained in plain English, for $49. Not fixed means full refund.
Request a fix

Last updated 2026-10-19.