Supabase database

Lovable authentication errors: fix “Database error saving new user” without opening your data

Two database errors are behind most broken sign-ups in Lovable apps that reach the Supabase forums: “Database error saving new user” and “new row violates row-level security policy for table profiles”. Both come from the step that creates a profile row for each new user. The quick fixes an AI builder usually reaches for, turning row level security off or adding a policy that says true, make sign-up work and let anyone on the internet read every user’s email and phone number. We reproduced both errors and all three fixes on Postgres 17 on 23 November 2026; the results are below.

TL;DR

  • “Database error saving new user” almost always means the trigger that copies a new user into profiles failed, so Supabase rolled the whole sign-up back.
  • “new row violates row-level security policy” at sign-up means the profile insert ran with no signed-in user: either inside that trigger, or from your app before the email was confirmed.
  • Turning RLS off on profiles, or adding using (true) / with check (true) policies, fixes sign-up and exposes every profile. In our test a logged-out visitor then read 2 of 2 users’ emails and phone numbers.
  • The fix: make the trigger function security definer with set search_path = '', keep RLS on, keep the owner-only read policy, and stop inserting profiles from the browser. After it, sign-up worked and the visitor and a stranger read 0 rows; the owner read 1.
  • Check which state your app is in with one query, below.

This guide is for founders and agencies with a Lovable app (or any Supabase app built with Bolt, Cursor or Claude Code) where new users can’t sign up, or where sign-up was “fixed” recently and nobody checked how. The results come from our own run on 23 November 2026: Postgres 17.11, Supabase-style roles (anon, authenticated, and supabase_auth_admin, the role Supabase Auth uses to write new users), two fake users, and the trigger and policies Lovable apps usually have. They show the pattern, not any particular app.

Which error do you have?

Open your browser’s developer tools on the sign-up page, sign up with a fresh address, and read the response of the request to /auth/v1/signup. Then check the Postgres logs in your Supabase dashboard (Logs, then Postgres) for the same minute, which show the real cause.

What you seeCause
App: Database error saving new user
Log: permission denied for schema public (or for table profiles)
The profile trigger runs as Supabase Auth’s role, which has no rights on your tables. Cause 1.
App: Database error saving new user
Log: new row violates row-level security policy for table "profiles"
The trigger has rights, but the insert policy checks auth.uid() = id, and nobody is signed in during sign-up. Cause 1.
App: sign-up succeeds, then an error toast with the same row-level security messageYour app inserts the profile from the browser right after signUp(); with email confirmation on there is no session yet. Cause 2.
App: Database error saving new user
Log: null value in column … violates not-null constraint, or column … does not exist
The trigger expects a field the form doesn’t send, or a column was renamed. Fix the trigger body; the security part of this guide still applies.

Cause 1: the profile trigger fails

Most Lovable apps create a profiles row for each new user with a trigger on auth.users. When the trigger fails, Postgres rolls back the whole insert, so the user isn’t created either, and Supabase Auth reports the generic “Database error saving new user”. In our run the failed sign-ups left auth.users with 0 rows.

This is the trigger as it is often written, without security definer:

supabase/migrations/…_profiles_trigger.sql (fails)
create or replace function public.handle_new_user()
returns trigger
language plpgsql
as $$
begin
  insert into public.profiles (id, email, full_name)
  values (new.id, new.email, new.raw_user_meta_data->>'full_name');
  return new;
end;
$$;

create trigger on_auth_user_created
  after insert on auth.users
  for each row execute function public.handle_new_user();

A trigger function without security definer runs as whoever caused the insert. For a sign-up that is supabase_auth_admin, the role Supabase Auth uses, and it has no rights in public. Our run gave exactly the error you see in the logs:

lab output, 23 Nov 2026
ERROR:  permission denied for schema public
CONTEXT:  PL/pgSQL function public.handle_new_user() line 1 at SQL statement

If someone has granted that role rights on profiles, the next error is the row level security one, because the usual insert policy is with check (auth.uid() = id) and auth.uid() is empty while Supabase Auth is creating the user:

lab output, 23 Nov 2026
ERROR:  new row violates row-level security policy for table "profiles"
CONTEXT:  SQL statement "insert into public.profiles ..."
          PL/pgSQL function handle_new_user() line 1 at SQL statement

Cause 2: the app inserts the profile before the user has a session

Some generated sign-up forms call supabase.auth.signUp() and then insert into profiles from the browser. With email confirmation switched on (the Supabase default), signUp() returns no session, so the insert goes out as a logged-out visitor and the owner-only policy refuses it. Our run, inserting as anon for a user who had just signed up:

lab output, 23 Nov 2026
ERROR:  new row violates row-level security policy for table "profiles"

The policy is doing its job here. The design is what is wrong: profile creation belongs in the database trigger, not in the browser.

The two quick fixes that expose every profile

Paste either error into an AI builder and these are the two answers you are most likely to get. Both make sign-up work. We applied each one, signed up two users, then read profiles as a logged-out visitor, as a stranger who is signed in, and as Alice, one of the two users.

Quick fix A: turn row level security off

do not ship
alter table public.profiles disable row level security;
lab output, 23 Nov 2026
reads: anon=2 stranger=2 owner(alice)=2
anon sees:
  alice@example.com|+447700900001
  bob@example.com|+447700900002

With RLS off, the default Supabase grants let anyone holding your public key, which ships in your web pages, read the whole table. That is finding PL-008.

Quick fix B: policies that say true

do not ship
create policy "Enable insert for all" on public.profiles
  for insert with check (true);
create policy "Enable read access for all users" on public.profiles
  for select using (true);
lab output, 23 Nov 2026
reads: anon=2 stranger=2 owner(alice)=2
carol signed up but has no profile row yet; anon writes it first:
  inserted as anon: not carol

The same full read, plus a write: a logged-out visitor created Carol’s profile with a name she didn’t choose. If your app inserts profiles from the browser (cause 2), anyone can get there first. These are findings PL-005 and PL-001. “Enable read access for all users” is the name of one of Supabase’s own policy templates, so it often lands in generated migrations unchanged.

The fix that keeps sign-up working and data private

One migration. It keeps row level security on and the owner-only policies as they are, and gives only the trigger the rights it needs:

supabase/migrations/…_fix_profiles_trigger.sql
-- 1. Undo the quick fixes, if they were applied
alter table public.profiles enable row level security;
drop policy if exists "Enable insert for all" on public.profiles;
drop policy if exists "Enable read access for all users" on public.profiles;

-- 2. Owner-only policies (skip any you already have)
drop policy if exists "own row read" on public.profiles;
create policy "own row read" on public.profiles
  for select to authenticated using ((select auth.uid()) = id);
drop policy if exists "own row update" on public.profiles;
create policy "own row update" on public.profiles
  for update to authenticated
  using ((select auth.uid()) = id) with check ((select auth.uid()) = id);

-- 3. The trigger runs as the function's owner, with a pinned search path
create or replace function public.handle_new_user()
returns trigger
language plpgsql
security definer
set search_path = ''
as $$
begin
  insert into public.profiles (id, email, full_name)
  values (new.id, new.email, new.raw_user_meta_data->>'full_name');
  return new;
end;
$$;

revoke execute on function public.handle_new_user() from public, anon, authenticated;

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();

Then remove the browser-side insert into profiles from your sign-up form; the trigger now does it. If the form collects a name or phone number, pass it as options.data in signUp() and read it from raw_user_meta_data in the trigger, as above. Treat those values as typed by the user: never copy a role or plan from them (see user_metadata vs app_metadata).

What our run showed after this migration:

lab output, 23 Nov 2026
users=2 profiles=2                         sign-up works, profile created
reads: anon=0 stranger=0 owner(alice)=1    each user sees only their own row
anon direct insert:
  ERROR:  new row violates row-level security policy for table "profiles"
signed-in user calling the trigger function:
  ERROR:  permission denied for function handle_new_user

Why this is safe: security definer lets only this one function write past row level security, and it only ever inserts the row for the user being created. set search_path = '' stops a look-alike table from being swapped in, which is why the table names inside are written in full. Trigger functions can’t be called through the API, and the revoke makes sure of it. Our SECURITY DEFINER guide explains when owner rights are dangerous; a sign-up trigger is one of the few places they are the right tool.

Check which state your app is in

Run this in the Supabase SQL editor. It changes nothing.

check-profiles.sql
select
  c.relrowsecurity                                   as rls_on,
  (select string_agg(polname, '; ') from pg_policy
     where polrelid = c.oid
       and 'true' in (pg_get_expr(polqual, polrelid),
                      pg_get_expr(polwithcheck, polrelid))) as always_true_policies,
  (select p.prosecdef from pg_proc p
     where p.oid = 'public.handle_new_user'::regproc) as trigger_is_definer,
  (select array_to_string(p.proconfig, ', ') from pg_proc p
     where p.oid = 'public.handle_new_user'::regproc) as trigger_settings
from pg_class c
where c.oid = 'public.profiles'::regclass;
ResultMeaning
rls_on falseQuick fix A is live. Anyone with your public key can read every profile. Apply the fix today.
always_true_policies not emptyQuick fix B (or similar) is live. Read the policy names: a read policy here exposes every row, an insert one lets anyone write.
trigger_is_definer falseCause 1: sign-ups will fail, or someone granted Supabase Auth’s role rights on your tables to make them pass.
trigger_settings has no search_path=The trigger works but its path isn’t pinned. Add set search_path = ''.

If your trigger function has a different name, find it with select tgname, tgfoid::regproc from pg_trigger where tgrelid = 'auth.users'::regclass and not tgisinternal;. The query errors if profiles or handle_new_user doesn’t exist; replace the names with yours.

Tell your AI builder the rule

prompt for Lovable or your AI builder
Sign-up is failing with "Database error saving new user".
Do not disable row level security and do not add policies
with using (true) or with check (true) on any table.
Fix it like this:
- The trigger on auth.users that creates the profile must be
  SECURITY DEFINER with SET search_path = '' and fully
  qualified table names, and REVOKE EXECUTE from public,
  anon, authenticated.
- Keep RLS on public.profiles with owner-only select and
  update policies using (select auth.uid()) = id.
- Remove any insert into profiles from the browser; pass form
  fields in signUp options.data instead.
Show me the migration before applying it.

Other Lovable sign-in errors that aren’t the database

  • The confirmation link opens localhost or the Lovable preview. The Site URL and Redirect URLs under Authentication, URL Configuration in Supabase still point at the preview. Add your real domain to both.
  • “Email not confirmed” at sign-in. Confirmation is on and the user hasn’t clicked the link yet. Leave it on for real users; turning it off lets anyone sign up with someone else’s address.
  • “Email rate limit exceeded”. Supabase’s built-in email sender is for testing and sends only a few emails an hour. Set up your own SMTP provider under Authentication settings before launch.
  • Google sign-in returns to an error page. The callback URL in your Google Cloud OAuth client must be your Supabase project’s /auth/v1/callback, and your domain must be in Supabase’s Redirect URLs.

None of these need a database change, so none of them is a reason to touch row level security.

Sources

The checks behind this guide, each with example code, a self-check and the fix.

Free check

Check your app for this, free.

Paste your public repo. PatchLabs rebuilds your database from its migrations, tests it as a visitor, a stranger and the owner, reads the code for keys and risky patterns, and hands you the fix.

First app free, fixes includedNever touches your database

Written by Manraj Singh Dhillon. Last checked 23 Nov 2026. Code samples are synthetic and run against your own project; nothing here names a real app. Spotted a mistake? Tell us.