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 ?
1 Answer
Reset to default 1Thanks 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 !