Supabase signUp: "User already registered", or no error and no email for an existing account

By AI App Medic · Updated · Supabase · Auth · Lovable · Sign-up

A person fills in your sign-up form and sees "Check your email to confirm your account". No email ever arrives. They try again, same thing. Or the form shows a red error instead:

AuthApiError: User already registered
status: 422
code: "user_already_exists"

Sometimes the first visible symptom is somewhere else entirely. The sign-up "works", and the next line of your code, the one that creates a row in profiles, fails:

insert or update on table "profiles" violates foreign key constraint "profiles_id_fkey"
Key (id)=(5b0c2e61-...) is not present in table "users".

All three come from the same place: the email already belongs to an account, and Supabase Auth is careful not to say so. Which of the symptoms you get depends on one project setting. Once you know how it behaves, the fix is a few lines in the sign-up handler and, usually, moving profile creation into the database.

What Supabase returns for an existing email

When signUp() is called with an email that is already in auth.users, the response depends on the account and on Confirm email (Authentication, Sign In / Providers, Email):

The placeholder exists to stop account enumeration: if the form answered "this email is taken", anyone could type addresses and learn who uses your app. The trade-off is that a generated sign-up form, which only checks error, tells the user to wait for an email that is never coming.

Step 1: confirm which case you have

Search for the email under Authentication, Users, or run this in the SQL editor:

select
  u.id,
  u.email,
  u.email_confirmed_at,
  u.created_at,
  array_agg(i.provider) as providers
from auth.users u
left join auth.identities i on i.user_id = u.id
where lower(u.email) = lower('person@example.com')
group by u.id;

If the row exists and email_confirmed_at is set, or providers lists a social provider, the sign-up is a repeat and Supabase is behaving as designed. If there is no row at all and still no email, the problem is delivery or rate limits, not this; see Supabase auth emails not sending and email rate limit exceeded.

You can also confirm it from the browser. In the Network tab, the /auth/v1/signup response for a repeat sign-up has "identities": [] and a user id that does not match the id in the dashboard.

Step 2: handle both outcomes in the sign-up handler

Check the error by its code, and check the empty identities array when there is no error. Be explicit about the array: a missing identities field is not the same as an empty one.

import { isAuthApiError } from "@supabase/supabase-js";

async function handleSignUp(email, password) {
  const { data, error } = await supabase.auth.signUp({
    email: email.trim(),
    password,
    options: { emailRedirectTo: window.location.origin + "/auth/callback" },
  });

  if (error) {
    if (isAuthApiError(error) && error.code === "user_already_exists") {
      return showExistingAccountMessage();
    }
    return setMessage(error.message);
  }

  const identities = data.user?.identities;
  const isRepeatSignup = !data.session && Array.isArray(identities) && identities.length === 0;
  if (isRepeatSignup) {
    // No email was sent and data.user.id is not a real user id.
    return showExistingAccountMessage();
  }

  if (data.session) {
    // Confirm email is off: the user is signed in now.
    return goToApp();
  }
  setMessage("Check your inbox to confirm your email.");
}

Whatever you do after a repeat sign-up, do not use data.user.id. It is random and belongs to nobody.

Step 3: move profile creation into the database

Generated apps very often do this right after signUp():

// fragile: runs for repeat sign-ups too
await supabase.from("profiles").insert({ id: data.user.id, full_name: name });

For a repeat sign-up that id does not exist in auth.users, so a foreign key rejects the insert, or, without one, you get a profile row that no account owns. It is also fragile for real sign-ups: with Confirm email on there is no session yet, so RLS usually blocks the insert with new row violates row-level security policy.

Create the profile in the database when the real user is created, and pass extra fields through options.data on sign-up:

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, jsonb_extract_path_text(new.raw_user_meta_data, 'full_name'))
  on conflict (id) do nothing;
  return new;
end;
$$;

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();
await supabase.auth.signUp({
  email,
  password,
  options: { data: { full_name: name } },
});

The placeholder user is never inserted into auth.users, so the trigger simply does not run for repeat sign-ups. Keep the function small: if it throws, every sign-up fails with Database error saving new user, which that guide covers in detail. Then delete orphan profiles left by the old code, after checking nothing else references them:

select p.id
from public.profiles p
left join auth.users u on u.id = p.id
where u.id is null;

Step 4: show one neutral message

For both the error and the placeholder case, show something like this, with working buttons:

If this email already has an account, sign in or reset your password.
Otherwise, check your inbox for the confirmation link.

[Sign in]  [Reset password]  [Continue with Google]

This covers the real situations: people who forgot they signed up, people who signed up with Google last time, and people who mistyped. It also keeps the protection Supabase gives you. If you show "this email is already registered" in the error case, you have told every visitor which addresses have accounts, even if Confirm email is on in production and off in staging. Keep the wording the same in both environments.

If a returning user then cannot sign in with a password, they probably never had one; Invalid login credentials explains how to tell and how password reset fixes it.

If you really need to tell users the email is taken

Some products, internal tools for example, decide that enumeration does not matter. In that case turn off Confirm email only if you accept unverified addresses, or check from a server function with the service role key and protect that function with a CAPTCHA and a strict rate limit. Never query auth.users from the browser and never expose the service role key to do it. For most consumer apps the neutral message is the better choice.

Admin API and invites

Server code that calls auth.admin.createUser() gets a clear error instead of a placeholder: HTTP 422 with code email_exists and the message A user with this email address has already been registered. Handle it in your import or invite scripts, and look the user up with auth.admin.listUsers() or your own profiles table if you need the existing id.

How to test it

Before launch, sign up four times with your own addresses: a new email, the same email again before confirming, the same email after confirming, and an email you first used with Google. Check the response in the Network tab and the message on screen each time, and confirm that only real users end up in profiles.

Prevention

Treat signUp() as having three successful outcomes, not one: signed in, confirmation sent, or already registered. Check error.code and the identities array on every call. Create profiles and other per-user rows with a trigger, never from the client right after sign-up. Use the same Confirm email setting in every environment so you test what production does, and keep the sign-in, reset and social login options one click away from the sign-up form.

FAQ

Why does Supabase signUp return no error for an existing email?

When Confirm email is on, Supabase does not tell the caller that an account already exists, so the sign-up form cannot be used to find out who uses your app. For an existing confirmed account it returns HTTP 200 with a placeholder user, no session and an empty identities array, and it sends no email.

How do I check if a user already exists after signUp in Supabase?

If error is null, data.session is null and data.user.identities is an empty array, the email already belongs to a confirmed account or to an account created with a social login. A real new sign-up comes back with one email identity in that array.

When does Supabase return User already registered?

When Confirm email is off (or Confirm phone is off, even if you do not use phone sign-in), signUp for an existing confirmed account returns HTTP 422 with code user_already_exists and the message User already registered. The admin API returns 422 with code email_exists for the same situation.

Why did my profile insert fail after signUp with a foreign key error?

The placeholder user returned for an existing account has a freshly generated random id that is not in auth.users. Inserting a profile with that id fails with violates foreign key constraint, or creates a row that belongs to nobody if there is no foreign key. Create profiles with a database trigger instead of from the client.

What happens if the existing account is not confirmed yet?

Supabase sends a new confirmation email, subject to the email rate limit, and returns the user with its email identity. From the front end it looks like a normal sign-up, which is fine: the person only needs to click the new link.

Should the sign-up form say this email is already taken?

We recommend against it. Show the same message for new and existing emails, such as check your inbox, and if you already have an account sign in or reset your password. Revealing which emails are registered helps attackers target your users.

Related guides