1

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;
  }
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
iKreateCode
  • 189
  • 3
  • 13
  • 1
    You're looking for the [`fetchSignInMethodsForEmail` method](https://pub.dev/documentation/firebase_auth/latest/firebase_auth/FirebaseAuth/fetchSignInMethodsForEmail.html). I'm pretty sure this was asked not too long ago, so I'll find a duplicate. – Frank van Puffelen Jun 20 '20 at 21:43
  • https://stackoverflow.com/a/68184676/5851439 – Stewie Griffin Jul 13 '21 at 12:04

1 Answers1

0

Such option does not exist in firebase auth library. But I will recommend you that you create a collection in firebase firestore database and store all of the emails in there and whenever needed read that file.

Aashar Wahla
  • 2,785
  • 1
  • 13
  • 19
  • and that would cause 'one more thing' to keep in sync. – keremistan Dec 01 '20 at 19:51
  • As Frank points out above, [it does exist.](https://pub.dev/documentation/firebase_auth/latest/firebase_auth/FirebaseAuth/fetchSignInMethodsForEmail.html) – John T Jul 02 '21 at 21:04
  • But that is the only way, else you will have to register a user to get an error that user is already there. – Aashar Wahla Jul 03 '21 at 22:54