2

I can’t solve this problem with Supabase and Flutter.

I sign up a user using the Supabase Flutter package :

await Supabase.instance.client.auth.signUp(
        email: email,
        password: password)

The email is confirmed, and the user shows up correctly in Supabase Auth with its ID. So far, everything is fine. But I'd like to handle the case where the user signs up with a already used email.

The problem is that when I call signUp with the same email again, it returns a new User object with a new ID with the same email address.

It should basically returns that the user or email is already existing ! Also, here's the Supabase Auth documentation regarding error codes : email_exists - Email address already exists in the system.

So this is the error.code that Supabase is supposed to return in my case, no ? What I am missing here ?

1
  • This question is similar to: How to check if user already exists in Supabase?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Oct 22 at 20:14

1 Answer 1

3

Thanks to this topic https://github.com/orgs/supabase/discussions/1282 I was able to solve it this way : Basically, when Email confirmation is enabled, even if the user already_exists, supabase still returns a User object. The solution is to check if (response.user!.identities!.isEmpty)

If identities is returned as an empty array, that's how you can check that the user already exists. Here's how I implemented it :

     final response = await Supabase.instance.client.auth.signUp(
        email: email,
        password: password,
      );

     if (response.user!.identities!.isEmpty) {
        throw AuthException(
          code: 'email_already_exists',
          'Email is already used.',
        );
      }

Hope that will help someone !

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.