最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to check if user already exists in Supabase? - Stack Overflow

programmeradmin2浏览0评论

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 ment 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.

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 ment 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.

Share Improve this question asked Sep 21, 2022 at 14:34 B45iB45i 2,6112 gold badges27 silver badges38 bronze badges 1
  • 1 interesting choice but according to github./supabase/supabase-js/issues/… you shouldn't need to check since the user is redirected via mail back to your application – zapl Commented Sep 21, 2022 at 16:42
Add a ment  | 

3 Answers 3

Reset to default 7

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.

Just go to providers and disable phone confirmation even if phone provider is disabled. Then you will get it in errors field. That user_already_exists

https://supabase./docs/reference/javascript/auth-signup

Going to the providers section and disabling phone confirmation fixes the issue, make sure to disable the phone confirmation and not just the phone provider, doing these will result in supabase finally giving the user already registered error.

Disabling The Phone Confirmation Under Providers (Phone)

发布评论

评论列表(0)

  1. 暂无评论