Supabase "Database error saving new user": how to fix it
Signup in your Lovable, Bolt or Cursor app fails with AuthApiError: Database error saving new user (HTTP 500, often unexpected_failure). Auth tried to insert into auth.users, something attached to that insert failed, and the whole signup rolled back. The browser message is a wrapper. The real cause is almost always a trigger on auth.users (usually handle_new_user) that copies the new user into public.profiles.
Stuck on this? Get it fixed for €49.
Fixed in 48 hours or you don't pay. Launch deal for the first 5 customers (normally €79). You get the tested fix as a pull request, so nothing changes until you merge it.
Get it fixed for €491. Read the real error in the logs
In the Supabase dashboard open Logs → Auth for the failed signup, then check the Postgres logs at the same time. Look for a line naming the function (for example PL/pgSQL function public.handle_new_user() line 3) and a SQLSTATE such as 42501 (permission denied) or 42P01 (relation does not exist). Fix that line, not the frontend form.
select tgname as trigger_name, tgfoid::regproc as function_name
from pg_trigger
where tgrelid = 'auth.users'::regclass and not tgisinternal;
2. Recreate the trigger function as security definer
Supabase Auth connects as supabase_auth_admin. A default (security invoker) function that inserts into public.profiles fails with permission denied because that role has no rights on your table. Supabase's recommended fix is a security definer function with a pinned empty search_path and a schema-qualified table name:
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;
$$;
-- keep / recreate the trigger 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 function public.handle_new_user();
If you set search_path = '' but write bare profiles instead of public.profiles, Postgres cannot find the table and you get the same generic signup error.
3. Create the profiles table the trigger expects
If the logs say relation "profiles" does not exist, the AI added the trigger but never created the table (or it was renamed / dropped). Create it, enable RLS, and add a simple owner policy:
create table if not exists public.profiles (
id uuid primary key references auth.users on delete cascade,
full_name text,
created_at timestamptz default now()
);
alter table public.profiles enable row level security;
create policy "own profile"
on public.profiles for all to authenticated
using (id = (select auth.uid()))
with check (id = (select auth.uid()));
grant select, insert, update, delete on public.profiles to authenticated;
If you do not need profiles at all, drop the trigger instead of guessing grants: drop trigger if exists on_auth_user_created on auth.users;. After Supabase's 30 October change, new tables also need explicit grants — see permission denied for table (42501).
4. Fill every NOT NULL column the trigger writes
A constraint on profiles (for example a required username) that the trigger does not set also rolls back signup. Make the column nullable or give it a default, and send values through signup metadata:
await supabase.auth.signUp({
email,
password,
options: { data: { full_name: name } } // becomes raw_user_meta_data
})
5. Retest with a brand-new email
Sign up a fresh address. Confirm a row appears in Authentication → Users and in public.profiles. In Lovable or Bolt, paste the exact Postgres log line into the chat so the agent fixes the trigger, not the React form. If login then fails with a missing session, see Auth session missing.
Quick checklist
- Auth + Postgres logs show the real SQLSTATE
handle_new_userissecurity definerwithsearch_path = ''- Table is
public.profiles(schema-qualified) and exists - RLS + grants are set; NOT NULL columns are filled
- New test user lands in both Auth and profiles
Stuck on this? Get it fixed for €49.
Fixed in 48 hours or you don't pay. Launch deal for the first 5 customers (normally €79). You get the tested fix as a pull request, so nothing changes until you merge it.
Get it fixed for €49Still stuck?
Mendlark fixes this kind of problem for a fixed €49 (launch price, normally €79). We agree the problem first, test the fix and send it as a pull request, so nothing changes in your app until you merge it. If we can't fix it, you don't pay. Get the €49 fix, or start with a free scan.
Not sure what else is wrong? Paste your app link into the free instant check and get a plain-English list of problems in seconds.