Fix guides

Supabase sign-up fails with "Database error saving new user": fix the profile trigger

New users cannot sign up (500, unexpected_failure, "Database error saving new user"), but your own account still works. Almost always the trigger that copies new users into a profiles table is failing. How to find the real Postgres error and fix the trigger without blocking sign-ups again.

Free · no card

Paste your error. Get a free diagnosis by email.

Tell us what broke and we’ll email you a short diagnosis: the likely cause and what to try first. Usually within a day.

No passwords or secret keys, please. We only use your email to reply about this.

What you are seeing

Why it happens

  1. A trigger on auth.users runs inside the same transaction as the sign-up. If the trigger function throws, Postgres rolls back the whole insert and Auth can only report a generic database error. The real reason is in the Auth and Postgres logs.
  2. The function is not security definer. Sign-ups are written by the supabase_auth_admin role, which only has the permissions it needs inside the auth schema, so a trigger running as that role is refused at public.profiles (permission denied for table profiles, 42501).
  3. The function sets search_path = '' (as Supabase recommends) but refers to profiles instead of public.profiles, so Postgres reports relation "profiles" does not exist (42P01). The same error appears if the table was dropped or renamed.
  4. A column on profiles was made not null or unique after the trigger was written, and the trigger does not fill it. Typical cases: a required username that only your sign-up form sends in metadata, so OAuth sign-ups insert null (23502), or two users with the same name (23505).
  5. The trigger reads metadata keys your sign-up never sends. Google and other OAuth providers fill different keys in raw_user_meta_data than your own form, so a value that is always there for email sign-ups can be missing for OAuth.
  6. Less often: a constraint someone added to auth.users itself, or a tool such as Prisma that changed permissions on the auth schema. Supabase lists both as known causes.

How to fix it

1. Read the real error first

In the Supabase dashboard, open Logs and check the Auth logs for the failed sign-up, then the Postgres logs at the same time. Look for the SQLSTATE and the line that says which function failed, for example: PL/pgSQL function public.handle_new_user() line 3. That tells you which of the causes above you have.

2. List the triggers on auth.users and their functions

select t.tgname as trigger_name,
       p.oid::regprocedure as function,
       p.prosecdef as is_security_definer,
       pg_get_userbyid(p.proowner) as owner
from pg_trigger t
join pg_proc p on p.oid = t.tgfoid
where t.tgrelid = 'auth.users'::regclass
  and not t.tgisinternal;

-- read the function body
select pg_get_functiondef('public.handle_new_user'::regproc);

3. Check which profile columns are required

select column_name, data_type, is_nullable, column_default
from information_schema.columns
where table_schema = 'public' and table_name = 'profiles'
order by ordinal_position;

-- every NOT NULL column without a default must be set by the trigger

4. Recreate the function the way Supabase documents it

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,
    coalesce(new.raw_user_meta_data ->> 'full_name', new.raw_user_meta_data ->> 'name'),
    new.raw_user_meta_data ->> 'avatar_url'
  );
  return new;
end;
$$;

-- (re)create the trigger only if it is missing
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();

5. Make required columns safe for every sign-up path

-- give required columns a default, or let them be null until onboarding
alter table public.profiles alter column username drop not null;

-- if usernames must be unique, let users pick one after sign-up
-- instead of failing the whole sign-up on a duplicate

6. Remove the duplicate client insert

If your app also inserts the profile from the browser right after signUp, delete that code. The trigger already creates the row, and a client insert either fails with new row violates row-level security policy or races the trigger. Update the row from the client later, with an owner update policy.

7. Tell your AI tool the rule

Add to your project rules (.cursorrules, Lovable knowledge, CLAUDE.md): Triggers on auth.users must be security definer with set search_path = '', must use schema-qualified names like public.profiles, and must never fail on missing metadata. Never insert users into auth.users with SQL; use the Auth API.

How to know it is fixed

Sign up with a brand-new email in a private window, then with Google (or whichever providers you offer). Both succeed, a matching row appears in public.profiles, and the Auth and Postgres logs show no error for those sign-ups. Inviting a user from the dashboard also works. Sources: Supabase KB: Database error saving new user, Supabase KB: errors when creating, updating, or deleting users, Supabase: User management (profile trigger), Supabase: Postgres triggers, PostgreSQL error codes. Related: Supabase RLS not working, Supabase login redirects to localhost.