tailor
tailor

Reputation: 443

How to check email already exists in Supabase table for signup in flutter?

Here I tried to move from firebase to Supabase in my flutter project. I stuck on first stage. onPress register button,

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

This is create new user in table. But How could I check email already exist for signup ?

Upvotes: 5

Views: 5647

Answers (1)

dshukertjr
dshukertjr

Reputation: 18612

Edited

Long answer short, you should not have to find out if a user exists or not in Supabase. You can read more about it here where the CTO of Supabase explains why, but exposing whether a certain user exists or not in public endpoint creates a security vulnerability.

signUp() method in Supabase will always behave the same on the client side whether there is already a user or not. On the backend, an email will be sent to the user, which will contain a confirmation link if the user did not exist prior, or a magic link if the user already did exist. If the user had already created an account and clicks on a magic link, the user is logged in as if they signed in using magic link, so no need to worry about anything further.

Original

I believe this would be the same in Firebase and Supabase (please correct me if I am wrong), but you will get an error if the user with the same email already existed.

You can get the error like this:

final response = await Supabase.instance.client.auth.signUp(email,pass);
final error = response.error;
if(error != null) {
  // Here you can handle case where there was an error signing up.
}

Upvotes: 6

Related Questions