2

How can I check if a user with the same email already exists when Enable email confirmations is turned on.

When Enable email confirmations are turned on an obfuscated / fake user object is returned by supabase, according to this comment it's a feature.

How can I check if the email already exists without turning off Email confirmation?

I tried passing using supabase.auth.api.getUser, but that needs JWT, not the user id.

B45i
  • 2,368
  • 2
  • 23
  • 33
  • 1
    interesting choice but according to https://github.com/supabase/supabase-js/issues/296#issuecomment-976200828 you shouldn't need to check since the user is redirected via mail back to your application – zapl Sep 21 '22 at 16:42

1 Answers1

0

Not sure if following is the correct way but I do it as follows (TypeScript):

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.');
  }
}

data.user?.identities?.length is 0 when the user is registered already.

Philipp
  • 794
  • 1
  • 7
  • 21