Why does Supabase signup fail with "Database error saving new user" in my Lovable or Bolt app?
Run a free check: FlowWatch signs up, logs in and runs a Stripe test checkout on your app, then scans for exposed keys. You get a shareable report. Run the free check at flowwatch.org
A new user fills in the signup form and gets "Database error saving new user". Your own account still logs in fine, so it's easy to miss until someone tells you. The catch is that nobody new can register while it's happening.
Supabase Auth itself almost never causes this error. It's a generic wrapper: Auth tries to insert the new row into auth.users, something else that runs in the same database transaction fails, the whole insert is rolled back, and Auth reports this message. Supabase's troubleshooting guide lists the usual culprits: a trigger or trigger function on auth.users that has an error, a constraint you added to auth.users that isn't being met, or a tool (Prisma is the named example) that broke the permissions on auth.users.
In Lovable, Bolt and similar builders, the cause is almost always the first one: the handle_new_user trigger that creates a profiles row for every new user.
Step 1: Read the real error in the logs
The signup response won't tell you the cause. The logs will.
- In the Supabase dashboard, open the Auth logs and find the failed signup. The message usually includes the underlying Postgres error and an SQLSTATE code.
- If it points at the database, open the Postgres logs for the same time. They often name the function and line, for example
PL/pgSQL function public.handle_new_user() line 3.
Match what you see to the causes below.
2. The trigger runs as a role that can't write your table (permission denied, 42501)
This is the most common cause. Signup writes to auth.users as Supabase's internal supabase_auth_admin role, and that role only has the privileges the Auth service needs. Postgres functions are security invoker by default, so a trigger function runs as whoever fired it. When it tries to insert into public.profiles, it does so as supabase_auth_admin and gets "permission denied". Grants or RLS policies for authenticated don't help, because that isn't the role doing the insert.
Fix: recreate the function as security definer, so it runs with the privileges of its owner (the postgres role in a standard project), pin search_path, and use fully qualified table names. This is the pattern in Supabase's own docs:
create or replace function public.handle_new_user()
returns trigger
language plpgsql
security definer set search_path = ''
as $$
begin
insert into public.profiles (id, first_name, last_name)
values (
new.id,
new.raw_user_meta_data ->> 'first_name',
new.raw_user_meta_data ->> 'last_name'
);
return new;
end;
$$;Keep set search_path = ''. A security definer function without a fixed search path is a security risk, and Supabase recommends always setting it. With an empty search path, every name has to be fully qualified (public.profiles, not profiles).
Don't "fix" this by turning off RLS on profiles. In a standard project the function runs as the postgres role, which bypasses RLS for this one insert. Every other query from your app still goes through your policies.
3. The table or column the trigger writes to doesn't exist (42P01)
If the logs say relation "profiles" does not exist, the trigger is inserting into a table that was never created, was renamed, or was dropped. This happens a lot after an AI edit rebuilds the schema or renames a table. It also happens if the function writes profiles without the schema prefix while search_path is empty.
Fix: create the table the function expects, or update the function to match the table you have now. If you no longer need the table, remove that insert or drop the trigger. You can view and edit functions on the Database → Functions page.
4. The insert breaks a constraint
If the logs show violates not-null constraint, violates check constraint or duplicate key value, the row your trigger builds doesn't fit the table. Typical reasons:
- A
NOT NULLcolumn (likeusernameorfull_name) is filled fromraw_user_meta_data, but that value isn't always there. Email signups only include what your form passes inoptions.data, and each OAuth provider sends different fields. - A
CHECKconstraint (username format, length) rejects what the metadata contains. - A unique column collides with an existing row.
Fix: make those columns nullable or give them defaults, use coalesce(...) in the function for metadata that might be missing, and test with every signup method you offer (email, magic link, each OAuth provider).
5. Someone inserted users with plain SQL
Supabase notes a related failure: if users were added straight into auth.users with an SQL INSERT (sometimes an AI tool does this to "seed" accounts) instead of through the Auth API, required columns can be left NULL where Auth expects an empty string. Auth logs may then show a scan error or "Database error querying schema" naming a column such as confirmation_token. Their guide shows how to set those values to ''. Going forward, create users through the Auth API or the dashboard, not raw SQL.
6. Re-test the way a stranger would
Your own login working tells you nothing here, because your account already exists. After any fix:
- Open your live site in a private window.
- Sign up with a brand-new email address (and once with each OAuth provider you offer).
- Confirm the new user appears under Authentication → Users and that its
profilesrow was created. - Log out, log back in, and load a page that reads the profile.
- Check the Auth and Postgres logs once more for new errors.
Do this again after any AI-generated change to tables, triggers or the profiles schema. Those edits are exactly what brings this error back.
Catch it before your users do
This error only hits new signups, so it can stay broken for days while your own account keeps working. FlowWatch can sign up as a new user on your live app every day, log in, and run a Stripe test checkout, and email you if one of those steps fails. It only uses Stripe's test card, and it stops before entering anything if your checkout is live. Start with the free check, which is one signup, login, and Stripe test checkout, plus a leak scan. Secrets in the report show only their last four characters.
Sources: Supabase troubleshooting guides "Database error saving new user" and "Errors when creating / updating / deleting users"; Supabase docs "User Management" (profiles table and handle_new_user trigger example); Supabase's response on supabase-js issue #1514 (Auth connects as supabase_auth_admin; functions are security invoker by default).
Questions: hello@flowwatch.org