← All errors · LovableSupabase auth errors
AuthApiError: Database error saving new user
Exact error
AuthApiError: Database error saving new user status: 500 code: unexpected_failure # Auth logs often show the real cause, for example: ERROR: permission denied for table profiles (SQLSTATE 42501) ERROR: relation "profiles" does not exist (SQLSTATE 42P01)
What it means
Supabase Auth tried to insert the new user into auth.users and something attached to that insert failed, so the whole signup was rolled back. It is almost always a trigger on auth.users, usually a handle_new_user function that copies each new user into a public.profiles table. Lovable and other AI builders often add this trigger when you ask for user profiles, and Supabase's own User Management starter uses the same pattern. The message is a generic wrapper: the real error is in the Auth and Postgres logs.
See also: official Supabase guide: Database error saving new user.
Likely causes
- The trigger function runs as security invoker (the default). Supabase Auth connects as the supabase_auth_admin role, which has no access to public.profiles, so the insert fails with permission denied (42501).
- The table the trigger writes to was never created, was renamed, or was dropped (relation does not exist, 42P01).
- The function sets search_path = '' but refers to profiles instead of public.profiles, so Postgres cannot find the table.
- A NOT NULL or unique column in profiles that the trigger does not fill, often a value read from raw_user_meta_data that the signup form never sends.
- A constraint added to auth.users itself, or a tool such as Prisma that changed permissions on the auth schema.
How to fix it
Find the real error. In the Supabase Dashboard open Logs → Auth, find the failed signup, then check the Postgres logs at the same time. Look for the function name (for example "PL/pgSQL function public.handle_new_user() line 3") and the SQLSTATE code.
List the triggers on auth.users and the functions they call:
select tgname as trigger_name, tgfoid::regproc as function_name from pg_trigger where tgrelid = 'auth.users'::regclass and not tgisinternal;Recreate the function as security definer with a pinned search_path and a schema-qualified table name. This is the fix Supabase recommends for permission errors:
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, new.raw_user_meta_data ->> 'full_name'); return new; end; $$;If the logs say relation does not exist, create the table the trigger expects, or remove the trigger if you do not need it:
create table if not exists public.profiles ( id uuid primary key references auth.users on delete cascade, full_name text ); alter table public.profiles enable row level security; -- or, if you don't need profiles at all: drop trigger if exists on_auth_user_created on auth.users;If a constraint fails (for example null value in column "username"), make that column nullable or give it a default, and send the values the trigger reads from your signup call:
await supabase.auth.signUp({ email, password, options: { data: { full_name: name } }, // becomes raw_user_meta_data });Sign up a new test user and check that a row appears in both Authentication → Users and public.profiles. In Lovable, Bolt, or Cursor, paste the exact Postgres log line into the chat so the agent fixes the trigger rather than the frontend:
Signup fails with AuthApiError: Database error saving new user (status 500, code unexpected_failure). The real error is in the Supabase Auth and Postgres logs, often a handle_new_user trigger on auth.users. Use the Postgres log line I paste below and fix the trigger or the table it writes to. Do not change the signup form until the database error is gone. <paste the Postgres log line here>
Still stuck after trying this? Get it fixed for $49, or you don't pay.
Prevent this next time
- Configure custom SMTP before launch so auth emails are not limited by the built-in test sender.
- Test signup, login, password reset and email confirmation on a staging project after every auth change.
FAQ
What does "AuthApiError: Database error saving new user" mean?
Supabase Auth tried to insert the new user into auth.users and something attached to that insert failed, so the whole signup was rolled back. It is almost always a trigger on auth.users, usually a handle_new_user function that copies each new user into a public.profiles table. Lovable and other AI builders often add this trigger when you ask for user profiles, and Supabase's own User Management starter uses the same pattern. The message is a generic wrapper: the real error is in the Auth and Postgres logs.
What usually causes it?
The trigger function runs as security invoker (the default). Supabase Auth connects as the supabase_auth_admin role, which has no access to public.profiles, so the insert fails with permission denied (42501). The table the trigger writes to was never created, was renamed, or was dropped (relation does not exist, 42P01). The function sets search_path = '' but refers to profiles instead of public.profiles, so Postgres cannot find the table. A NOT NULL or unique column in profiles that the trigger does not fill, often a value read from raw_user_meta_data that the signup form never sends. A constraint added to auth.users itself, or a tool such as Prisma that changed permissions on the auth schema.
How do I fix it?
1. Find the real error. In the Supabase Dashboard open Logs → Auth, find the failed signup, then check the Postgres logs at the same time. Look for the function name (for example "PL/pgSQL function public.handle_new_user() line 3") and the SQLSTATE code. 2. List the triggers on auth.users and the functions they call: 3. Recreate the function as security definer with a pinned search_path and a schema-qualified table name. This is the fix Supabase recommends for permission errors: 4. If the logs say relation does not exist, create the table the trigger expects, or remove the trigger if you do not need it: 5. If a constraint fails (for example null value in column "username"), make that column nullable or give it a default, and send the values the trigger reads from your signup call: 6. Sign up a new test user and check that a row appears in both Authentication → Users and public.profiles. In Lovable, Bolt, or Cursor, paste the exact Postgres log line into the chat so the agent fixes the trigger rather than the frontend:
Last checked against official docs on . Sources: Official Supabase Knowledge Base: Database error saving new user, Official Supabase Knowledge Base: Errors when creating, updating, or deleting users, supabase-js issue #1514 (Supabase team explanation).
Related errors
- relation "public.x" does not exist
- new row violates row-level security policy for table
- Email rate limit exceeded
More Lovable errors and fixes →
Get new fixes weekly
No spam. Unsubscribe anytime. Privacy