LeakPatrol › Guides

Supabase "Database error saving new user": the real cause and the safe fix

By LeakPatrol · Updated 20 November 2026

Your sign-up form fails with AuthApiError: Database error saving new user (status 500), and no user is created. Supabase Auth itself is almost never the problem. In nearly every case a trigger on auth.users, usually called handle_new_user, tries to insert a row into your profiles table and that insert fails. The error message hides the real reason, so the first step is to find it.

Step 1: find the real error

In the Supabase dashboard open Logs → Postgres (or Auth logs) and look for an ERROR at the moment of the failed sign-up. You'll see one of the messages below. Then list the triggers on auth.users:

select tgname, tgfoid::regproc as function
from pg_trigger
where tgrelid = 'auth.users'::regclass and not tgisinternal;

The usual causes

1. permission denied for table profiles

The trigger runs as the Auth service's own role, which isn't allowed to write to your public tables. The function needs to run as its owner instead, with security definer. This is the most common cause, especially when an AI tool wrote the trigger.

2. relation "profiles" does not exist

The function says profiles instead of public.profiles, and the Auth role's search path doesn't include public. Always use the full name.

3. null value in column ... violates not-null constraint

The profile table has a required column (username, full_name) and the trigger fills it from raw_user_meta_data, but the sign-up didn't send that field. Either send it in options.data on signUp, give the column a default, or use coalesce(new.raw_user_meta_data->>'full_name', '').

4. duplicate key value violates unique constraint

A unique username taken from metadata clashes with an existing one, or a profile row was left behind after a user was deleted. Use on conflict (id) do nothing for the id, and make usernames unique in your app before sign-up.

5. Type mismatch

profiles.id is bigint or text instead of uuid. It should be uuid and reference auth.users(id).

The safe trigger

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)
  values (new.id, coalesce(new.raw_user_meta_data->>'full_name', ''))
  on conflict (id) do nothing;
  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 function public.handle_new_user();

security definer lets the function write to profiles; set search_path = '' stops anyone from tricking it into using a different table, which is why every name inside is written as public.….

What not to do

Once sign-up works, users still need policies to read and update their own profile. If those are missing, reads come back empty: see why Supabase returns an empty array, or build them with the RLS policy generator.

A prompt to paste into Lovable, Bolt or Cursor

Sign-up fails with "Database error saving new user". Fix it safely:
1. Show me every trigger on auth.users and the function it calls.
2. Rewrite the function as SECURITY DEFINER with set search_path = '',
   use full names (public.profiles), coalesce() any value read from
   raw_user_meta_data, and add "on conflict (id) do nothing".
3. Make sure profiles.id is uuid and references auth.users(id).
Keep RLS enabled on profiles. Do not grant anything to anon, do not
disable RLS, and do not use the service_role key in the frontend.

After launch, LeakPatrol's free scan checks your live app for leaked keys and other common mistakes in about a minute.

Check your app in a minute

Free, read-only, no sign-up. Every problem comes with a plain-English fix and a prompt for your AI tool.

Get the 10-point checklist

Every check we run on AI-built apps, with how to do each one yourself. Straight to your inbox.

Questions

What does "Database error saving new user" mean in Supabase?

Supabase Auth could not save the new user because something in the database failed during the insert, almost always a trigger on auth.users that creates a row in a profiles table. The Postgres logs show the real error.

How do I fix the handle_new_user trigger?

Make the function SECURITY DEFINER with set search_path = empty, refer to tables by full name such as public.profiles, use coalesce for values from raw_user_meta_data, and add on conflict (id) do nothing.

Should I disable RLS on the profiles table to fix sign-up?

No. A SECURITY DEFINER trigger does not need RLS disabled, and turning it off lets anyone with your public anon key read and change every profile.

Where do I see the real error behind it?

In the Supabase dashboard under Logs, Postgres (or Auth). Look for the ERROR line at the time of the failed sign-up, for example permission denied, relation does not exist, or a not-null violation.

More guides