So basically, I have the following code:
Future<bool> registerUser(String email, String password, String username) async {
AuthResponse res = await supabase.auth.signUp(
email: email,
password: password,
);
if (res.user != null) {
return true;
} else {
return false;
}
}
It is called in my register form and works if the registration is a success. If it fails, however, it seems to keep hanging somewhere in the signUp() method cause it gives me the error in the console (e.g. password is too short) but does not return true or false later on in the function. Thus, is there a way to just catch the exception and then 'quit' the signUp process?
I played around with a setState and a simple Text widget to see what the registerUser method returned, but it does not seem to return anything when something goes wrong in the registration process.
You can catch the error and return false, like
Future<bool> registerUser(
String email, String password, String username) async {
try {
AuthResponse res = await supabase.auth.signUp(
email: email,
password: password,
);
return res.user != null;
} catch (e) {
return false;
}
}