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

dart - Flutter - Check if user exists in Supabase Auth - Stack Overflow

programmeradmin3浏览0评论

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 ?

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 ?

Share Improve this question asked 2 days ago leujileuji 1011 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Thanks to this topic https://github/s/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 !

发布评论

评论列表(0)

  1. 暂无评论