Skip to content
VibeSafeDaily

Auth

Supabase sign-up fails with "Database error saving new user"

Cataloged November 28, 2026 · Supabase

Symptom

This applies when sign-up, an invite from the Supabase dashboard, or a user inserted from the table editor fails with the message "Database error saving new user", or when login fails with "error update user's last_sign_in field". If this project does not use Supabase Auth, this card does not apply. Supabase is the platform tag because the failure is in that project's database. The pages on this card describe the role Auth uses and a trigger on auth.users. They do not describe a bug in one generator, so the same failure happens on any Supabase project whose trigger on auth.users still runs as security invoker and then touches public.profiles, including an app an AI coding tool generated. This card does not say Lovable or Bolt generate that trigger. Supabase's page "Errors when creating / updating / deleting users" says this kind of failure returns HTTP 500 with code unexpected_failure, and "Database error saving new user" is one of the messages it lists. Supabase's page "Database error saving new user" says you generally get that error when inviting a user from the dashboard or inserting a user in the table editor, and that you may also see it in logs in connection with failed signups. It says the error is normally a side effect of a database transaction. supabase-js issue 1514, opened July 29, 2025, is titled "Signup/Login fails due to internal update on profiles — permission denied (SQLSTATE 42501)". The report says both signup and login fail with a 500 error. The signup log it prints is "Database error saving new user" and "permission denied for table profiles (SQLSTATE 42501)". The login line in that report uses the words error update user's last_sign_in field, with a typographic apostrophe, followed by a colon and ERROR: permission denied for table profiles. The April 28, 2026 comment spells the wrapper with a straight apostrophe, as "error update user's last_sign_in field", and this card uses that straight spelling. The report says row level security was enabled on profiles, that authenticated had select, insert, update, and delete, and that the insert and update policies were permissive, written as with check (true). It says that after disabling row level security entirely, login then succeeded. This card does not print the project id from that report, and it does not say to turn row level security off. A comment on the issue by mandarini, dated April 28, 2026, says Supabase Auth does not write to public.profiles during signup or login. That comment says a check of the Auth server source found zero references to profiles. It says the two messages are generic wrappers Auth uses when any statement against auth.users fails: "Database error saving new user" wraps the INSERT INTO auth.users during signup, and "error update user's last_sign_in field" wraps the UPDATE auth.users SET last_sign_in_at = now() that runs when a session is created or refreshed. It says a trigger on auth.users is what actually fails, and that the failure aborts the whole transaction, so the original Auth statement reports the wrapper. It says Auth connects to Postgres as supabase_auth_admin, not as authenticated. It says plpgsql trigger functions run as security invoker by default, so they inherit the caller's role, and this trigger runs as supabase_auth_admin, which has no privileges on public.profiles no matter what is granted to authenticated. An earlier comment, by 7ttp on January 29, 2026, says the same thing in shorter form: the trigger on auth.users is security invoker, it runs with supabase_auth_admin permissions that cannot access the profiles table, and security definer makes it run with postgres role permissions. GitHub records that comment's author association as MEMBER. The April 28 comment's author association is CONTRIBUTOR. The longer guide linked from this page is "Lovable Supabase data exposed: check RLS on your own app", because turning row level security off is the wrong repair. The catalog card "Supabase tables ship with row level security off" is the same warning for a table left open.

Root cause

PostgreSQL's overview of trigger behavior says a trigger runs in the same transaction as the statement that fired it, so if the trigger errors, the statement is rolled back too. The same page says the trigger runs as the role that queued the event, unless the function is marked SECURITY DEFINER, in which case it runs as the function owner. PostgreSQL CREATE FUNCTION says SECURITY INVOKER is the default and runs with the privileges of the caller, and SECURITY DEFINER runs with the privileges of the owner. The user who creates the function becomes the owner. CREATE OR REPLACE FUNCTION does not change that ownership, and it changes the function without dropping the triggers that call it. The April 28, 2026 comment on supabase-js issue 1514 says the caller in this failure is supabase_auth_admin. Supabase's page "Errors when creating / updating / deleting users" says that role only has the permissions it needs for Auth, so a trigger it runs that touches a table outside the auth schema hits a permission error. The page's trigger example includes "permission denied for table profiles (SQLSTATE 42501)". It says a security definer function keeps the privileges of the database user that created it, and that as long as that user is the postgres role, the trigger can use tables outside auth. Supabase's managing user data page says a function created in the Dashboard or by a migration is owned by postgres, which bypasses row level security. That is why the trigger can insert the profile while a client insert cannot. The repair those pages and the comment describe is security definer, set search_path = '', and schema-qualified names such as public.profiles. The comment prints insert into public.profiles (id) values (new.id). The managing user data template uses language plpgsql security definer set search_path = '' and inserts into public.profiles (id, first_name, last_name). Its caution says that with search_path = '', Postgres cannot find an unqualified name like profiles, the trigger then fails, and every sign-up fails with "Database error saving new user". PostgreSQL CREATE FUNCTION says a SECURITY DEFINER function should set search_path so it does not include schemas writable by untrusted users. The example on that page is SET search_path = admin, pg_temp. The empty string is the Supabase template, not that example. Supabase's database functions page says to prefer security invoker, which is the default, and that a security definer function must set search_path. It says that with search_path = '' you name the schema on every relation. It also says a security definer function can return rows the caller is not allowed to read, because it runs as its owner, and that any role can call such a function by default, including anon. Pinning search_path does not change who can call it. PostgreSQL CREATE FUNCTION says a new function grants execute to PUBLIC, and that you revoke that grant when you want to limit who can run a security definer function. This card does not tell you to revoke execute on the signup trigger. CREATE TRIGGER says the function it runs is declared with no arguments and return type trigger, and that it is executed when the trigger fires. The trigger pages opened for this card do not say that function is called through rpc(). The catalog card "A database function returns rows the table policy hides" is the one for a security definer function the Data API can call. Read the Postgres log before you pick a repair, because the troubleshooting pages list other causes under the same wrapper. "Database error saving new user" says a trigger on auth.users that errors, a constraint on auth.users that is not met, and Prisma having broken the permissions on auth.users. Its example for a missing table is relation "profiles" does not exist (SQLSTATE 42P01), with context PL/pgSQL function public.handle_new_user() line 3, and the cause it gives is that the function inserts into a table that does not exist. The dashboard-errors page has a separate 42P01 example, relation "public.profiles" does not exist, which it labels as a broken search path or an incorrect name, and a missing column, column "updated_at" of relation "profiles" does not exist (SQLSTATE 42703). Its constraint example is SQLSTATE 23503, an update or delete on auth.users that still references profiles through profiles_id_fkey. That example is not the signup insert. The example profiles table in the security definer section declares username text unique and constraint username_length check (char_length(username) >= 3). The insert in that same example writes id, full_name, and avatar_url, not username. This card does not say that check is what failed unless your log names it. Supabase's page "Resolving 500 Status Authentication Errors" says an error like "must be owner of..." can mean supabase_auth_admin lost privileges on tables in the auth schema, often after a faulty migration from an external ORM such as Prisma. A different log on the "Database error saving new user" page is "Database error querying schema", from a NULL confirmation_token: converting NULL to string is unsupported. That page says this happens when a user is inserted with SQL directly, including by an AI tool, instead of through the Auth API. That message is not the one in this card's title. The managing user data page says not to insert the profile from the client after sign-up. With no insert policy, that client insert fails with new row violates row-level security policy for table "profiles". The same page says users can edit their own user metadata, so a role or a tenant id stored there lets a user grant themselves access, and not to use user metadata in authorization. Do not copy a role or a tenant id from new.raw_user_meta_data in this trigger. The page's own example copies first_name and last_name only. The catalog card "Any user can make themselves admin through user_metadata" is that failure. The 42501 in issue 1514 is supabase_auth_admin lacking privileges on public.profiles while the trigger runs. It is not the missing-grant failure on a newly created public table. That one is the catalog card "New Supabase tables fail with 'permission denied' (42501) after October 30".

Before and after

The before lines are the two wrappers named in the April 28, 2026 comment on supabase-js issue 1514. That comment says "Database error saving new user" wraps INSERT INTO auth.users during signup, and "error update user's last_sign_in field" wraps UPDATE auth.users SET last_sign_in_at = now() when a session is created or refreshed. The apostrophe in that comment is straight. The after lines are from the function that same comment prints: security definer, set search_path = '', and insert into public.profiles (id). Supabase's managing user data page puts language plpgsql security definer set search_path = '' on one line, and its insert also names public.profiles. This pair does not add a role column. The comment does not print a failing function body, so the before block is the wrapper text, not a broken CREATE FUNCTION.

Before

Database error saving new user
error update user's last_sign_in field

After

language plpgsql
security definer
set search_path = ''
insert into public.profiles (id) values (new.id);

Fix prompt

In this project only. Do not open a Supabase project you do not own. Do not print keys, tokens, passwords, or user rows. Do not disable row level security. Do not grant privileges on public.profiles to anon, to authenticated, or to supabase_auth_admin to make this error go away. Do not drop public.profiles. Do not insert a row into auth.users with SQL. Do not send a signup request to a project this one does not own.

1. This prompt applies if this project uses Supabase Auth and sign-up, a dashboard invite, or login fails with "Database error saving new user" or "error update user's last_sign_in field". Supabase's page "Errors when creating / updating / deleting users" says those failures can return HTTP 500 with code unexpected_failure. If this project does not use Supabase Auth, say so and stop. The failure is a trigger on auth.users in this database. It is not a bug in the tool that generated the app. The same failure happens on any Supabase project whose trigger on auth.users runs as security invoker and touches a table that role cannot use, regardless of which tool generated the app.

2. Read the real error before you change SQL. Supabase's page "Database error saving new user" says to start in the Auth logs, then open the Postgres logs. Paste me the Postgres error, the SQLSTATE, and the function name from the context line. Do not guess which cause it is. If you cannot read the logs, stop and tell me to paste them. Documented examples you may match against that text, and only against that text: permission denied for table profiles (SQLSTATE 42501); relation "profiles" does not exist (SQLSTATE 42P01) in public.handle_new_user(); relation "public.profiles" does not exist (SQLSTATE 42P01); column "updated_at" of relation "profiles" does not exist (SQLSTATE 42703); a constraint on auth.users that is not met; Prisma having broken permissions on auth.users. If the Auth log is "Database error querying schema" and the detail is a NULL confirmation_token, converting NULL to string is unsupported, stop the trigger edit. That page says this comes from a direct SQL insert, including one by an AI tool. Its fix is update auth.users set confirmation_token = '' where confirmation_token is null, and to swap in the column name the log actually prints. Do not update any other column. Do not invent a second statement.

3. In the SQL editor of this project, list the triggers on auth.users and the security settings of their functions. pg_trigger.tgname is the trigger name, tgfoid is the function, tgrelid is the table, and tgisinternal is true when Postgres generated the trigger, usually for a constraint. pg_proc.prosecdef is true when the function is security definer. pg_proc.proconfig holds the function's local settings, including a search_path when one is set. PostgreSQL's object-identifier page says a schema-qualified name is valid regclass input, as in myschema.mytable. Run:
select t.tgname, p.proname, p.prosecdef, p.proconfig from pg_trigger t join pg_proc p on p.oid = t.tgfoid where t.tgrelid = 'auth.users'::regclass and not t.tgisinternal;
Then run the query from "Resolving 500 Status Authentication Errors" for the function the log names: select pg_get_functiondef(oid) from pg_proc where proname = '<FUNCTION NAME>'; Replace <FUNCTION NAME> with the name from the log or from the query above. The documented example name is handle_new_user. Do not assume that is the name in this project. Show me the rows and the definition. Do not drop anything in this step.

4. If the log is permission denied for table profiles and prosecdef is false, change that function to security definer with an empty search_path and schema-qualified names. The April 28, 2026 comment prints this shape, and the insert writes only id:
create or replace function public.handle_new_user()
returns trigger
language plpgsql
security definer
set search_path = ''
as $$
begin
  insert into public.profiles (id) values (new.id);
  return new;
end;
$$;
Use the function name this project already has. Keep every column the existing function inserts, and schema-qualify each table. The managing user data template writes id, first_name, and last_name from new.raw_user_meta_data, with language plpgsql security definer set search_path = ''. Its caution says an unqualified profiles with search_path = '' makes every sign-up fail with "Database error saving new user". Put the schema in front of every table, function, and type in the body that is not built in. Prefer create or replace when the arguments stay the same. PostgreSQL says CREATE OR REPLACE FUNCTION does not change ownership or privileges and does not drop triggers that call the function. It also says CREATE OR REPLACE cannot change the return type. The dashboard-errors page's other procedure is DROP FUNCTION <function name>() CASCADE, which drops the trigger, then recreate the function and the trigger. Do not drop a function you have not shown me. If you must recreate the trigger, use the statement that page and the managing user data page print:
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();
Use this project's trigger name and function name. PostgreSQL CREATE TRIGGER says FUNCTION and PROCEDURE are equivalent there, and that PROCEDURE is historical and deprecated. The Supabase pages still print execute procedure. Do not change a trigger that already fires just to swap that keyword. The function has to be owned by postgres. The dashboard-errors page says a security definer function keeps the privileges of the user that created it, and that the postgres role is the one that can use tables outside auth. The managing user data page says a function created in the Dashboard or by a migration is owned by postgres. Run this in the SQL editor. Do not grant supabase_auth_admin privileges on public.profiles. The comment's repair for this 42501 is security definer, not a grant.

5. Match the other log texts to the page that states them, and do not use step 4 for a different SQLSTATE. If the log is relation "profiles" does not exist (42P01), the troubleshooting page says the function inserts into a table that does not exist. Create that table if this project is supposed to have it, or remove the reference if it is not. Do not point the insert at some other table. If the log is column "updated_at" of relation "profiles" does not exist (42703), or any other missing column, change the insert list to columns that exist on that table. If the log names a constraint the inserted values do not meet, change those values so they meet it. Do not drop the constraint unless I ask. The example table on the dashboard-errors page has username text unique and constraint username_length check (char_length(username) >= 3), and the insert in that example does not write username. Use that only when the log names that constraint. The page's 23503 example is an update or delete that violates profiles_id_fkey. Do not treat it as the signup insert unless the log says 23503. If the log says must be owner of an object in the auth schema, follow "Resolving 500 Status Authentication Errors". That page says supabase_auth_admin may have lost ownership of auth objects after a faulty ORM migration, and it names Prisma. Its statement is ALTER <object type> <auth.object_name> OWNER TO supabase_auth_admin, for an object in the auth schema that some other role owns, and it says to contact Support when the owner is supabase_admin. Do not run that statement on public.profiles.

6. Remove a client insert into public.profiles that runs after signUp. The managing user data page says the trigger already creates the row, and a client insert fails with new row violates row-level security policy for table "profiles" when the table has no insert policy. Do not add an insert policy for anon or for authenticated to make that second insert succeed. The policies that page prints are select and update, to authenticated, limited to the signed-in user's own id with (select auth.uid()) = id.

7. In the trigger, do not copy a role or a tenant id from new.raw_user_meta_data. The managing user data page says users can edit their own user metadata, so a role or a tenant id stored there lets a user grant themselves access. The page's example copies first_name and last_name only. Display fields of that kind may stay. The catalog card "Any user can make themselves admin through user_metadata" is the case where a role is taken from that metadata. Do not add a role column to this insert.

8. Leave row level security enabled on public.profiles. The issue 1514 report says that disabling it was followed by login succeeding. The April 28 comment says Auth does not write to public.profiles, and that permissive policies on authenticated do not fix a trigger that runs as supabase_auth_admin. The managing user data page says to enable row level security on that table. Do not set it to off. Do not revoke execute on this trigger function in this prompt. PostgreSQL CREATE FUNCTION says a new function grants execute to PUBLIC and shows a revoke for a security definer function you want only some users to run. Supabase's database functions page says a security definer function can be called by any role by default, including anon, and it shows revoke execute from public and from anon. Those pages do not say a function that returns trigger is called with rpc(). The catalog card "A database function returns rows the table policy hides" is the one for a security definer function the Data API can call. Do not apply that revoke here unless I ask.

9. Show me the function definition and the diffs. Do not deploy. Do not print keys or user rows. Do not edit unrelated files.

Paste this into the coding tool that has your own project open.

2-minute self-check

These steps are for an app you own. Do not run them against someone else's project.

  1. In the SQL editor of a Supabase project you own, list triggers on auth.users and the security settings of their functions. pg_trigger documents tgname, tgfoid, tgrelid, and tgisinternal. pg_proc documents prosecdef and proconfig. PostgreSQL's object-identifier page says a schema-qualified name such as myschema.mytable is valid regclass input. Run: select t.tgname, p.proname, p.prosecdef, p.proconfig from pg_trigger t join pg_proc p on p.oid = t.tgfoid where t.tgrelid = 'auth.users'::regclass and not t.tgisinternal; prosecdef false means the function is not security definer. CREATE FUNCTION says security invoker is the default. For the function the row names, also run select pg_get_functiondef(oid) from pg_proc where proname = '<FUNCTION NAME>'; as printed on Supabase's page "Resolving 500 Status Authentication Errors". The definition should say security definer and set search_path = '', and the insert should name public.profiles, not profiles. Do not run this in a project you do not own.
  2. In that same project, confirm row level security is still enabled on public.profiles. pg_tables.rowsecurity is true when row security is enabled. Run: select rowsecurity from pg_tables where schemaname = 'public' and tablename = 'profiles'; The value should be true. Do not set it to false. The issue 1514 report says disabling row level security was followed by login succeeding. That is not the repair. The managing user data page says to enable row level security on public.profiles.
  3. On a Supabase project you own, sign up one throwaway user and confirm a row appears in public.profiles for that user. The managing user data page says the trigger inserts that row on sign-up, and that a failing trigger can block sign-ups, so the sign-up has to be tested. Prefer a project your users do not already depend on, when you have one. Do not print the row. Do not point this sign-up at a project you do not own.

Common questions

Disabling row level security on profiles made login succeed. Should I leave it off?

No. The report on supabase-js issue 1514 says that after row level security was disabled entirely, login then succeeded. The April 28, 2026 comment on that issue says Supabase Auth does not write to public.profiles, and that grants and permissive policies on the authenticated role do not fix a trigger that runs as supabase_auth_admin. Supabase's managing user data page says to enable row level security on public.profiles. Leave it enabled. The longer guide on this page, Lovable Supabase data exposed, is the check for a table left open. The catalog card "Supabase tables ship with row level security off" is the same warning.

authenticated already has every privilege on profiles, and the policies use with check (true). Why does sign-up still return Database error saving new user?

The April 28, 2026 comment on supabase-js issue 1514 says Auth connects as supabase_auth_admin, not as authenticated. It says plpgsql trigger functions run as security invoker by default, so the trigger runs as supabase_auth_admin, which has no privileges on public.profiles no matter what you grant to authenticated. PostgreSQL's trigger overview says a trigger runs as the role that queued the event unless the function is SECURITY DEFINER, in which case it runs as the owner. The repair the comment prints is security definer, set search_path = '', and insert into public.profiles. Supabase's managing user data page uses that same security definer and empty search_path, and its caution says an unqualified name profiles makes every sign-up fail with Database error saving new user. Read the Postgres log first. A 42P01, a 42703, a constraint, or a NULL confirmation_token is a different repair on the troubleshooting pages, not this grant.

The app also inserts the profile after signUp and gets new row violates row-level security policy for table "profiles". Do I add an insert policy?

No. Supabase's managing user data page says not to insert the profile from the client after sign-up. The trigger already creates the row, and with no insert policy the client insert fails with that message. The policies that page prints are select and update for authenticated, each limited to the signed-in user's own id. Do not copy a role or a tenant id from raw_user_meta_data in the trigger. That page says users can edit their own user metadata, so a role or a tenant id there lets a user grant themselves access. Its example copies first_name and last_name only. The catalog card "Any user can make themselves admin through user_metadata" is the role case.

Longer guide

Sources

Same symptom

Same platform