In flutter i want to check if the user's email exists in the firebase auth without registering the user. If the email does exist then it would show a different form to tell the user to login. Otherwise they would go to a questions page which they would finish first before registering the user onto the database.
My code that calls the firebase create user method
void validateAndSubmit() async {
setState(() {
_errorMessage = "";
_isLoading = true;
});
if (validateAndSave()) {
String userId = "";
try {
userId = await widget.auth.signUp(_email, _password);
print('Signed up user: $userId');
setState(() {
_isLoading = false;
});
} catch (e) {
print('Error: $e');
setState(() {
Navigator.push(context,
MaterialPageRoute(builder: (context) => QuestionsPage()));
_isLoading = false;
_errorMessage = e.message;
_formKey.currentState.reset();
});
}
}
}
My file where the auth method code is stored
Future<String> signUp(String email, String password) async {
AuthResult result = await _firebaseAuth.createUserWithEmailAndPassword(
email: email, password: password);
FirebaseUser user = result.user;
return user.uid;
}