Chek if an email is already registered on signup

I want before signin up, to check if an email is already registered. I found this code in stackoverflow ( source )

const [errorMsg, setErrorMsg] = useState<string | null>(null);
const [successMsg, setSuccessMsg] = useState<string | null>(null);

async function signUp(formData: Values) {
  const { data, error } = await supabase.auth.signUp({
    email: formData.email,
    password: formData.password,
  });

  if (error) {
    setErrorMsg(error.message);
  } else if (data.user?.identities?.length === 0) {
    setErrorMsg('User already registered');
  } else {
    setSuccessMsg('Success! Please check your inbox.');
  }
}


Can I trust the logic on identities length ?
Was this page helpful?