signInWithEmailAndPassword method

Future<UserCredential> signInWithEmailAndPassword({
  1. required String email,
  2. required String password,
})

Attempts to sign in a user with the given email address and password.

If successful, it also signs the user in into the app and updates any authStateChanges, idTokenChanges or userChanges stream listeners.

Important: You must enable Email & Password accounts in the Auth section of the Firebase console before being able to use them.

A FirebaseAuthException maybe thrown with the following error code:

  • invalid-email:
  • Thrown if the email address is not valid.
  • user-disabled:
  • Thrown if the user corresponding to the given email has been disabled.
  • user-not-found (deprecated):
  • Thrown if there is no user corresponding to the given email. Note: This code is no longer returned on projects that have email enumeration protection enabled (the default for new projects since September 2023). Use invalid-credential instead.
  • wrong-password (deprecated):
  • Thrown if the password is invalid for the given email, or the account corresponding to the email does not have a password set. Note: This code is no longer returned on projects that have email enumeration protection enabled (the default for new projects since September 2023). Use invalid-credential instead.
  • too-many-requests:
  • Thrown if the user sent too many requests at the same time, for security the api will not allow too many attempts at the same time, user will have to wait for some time
  • user-token-expired:
  • Thrown if the user is no longer authenticated since his refresh token has been expired
  • network-request-failed:
  • Thrown if there was a network request error, for example the user doesn't have internet connection
  • invalid-credential:
  • Thrown if the email or password is incorrect. On projects with email enumeration protection enabled (the default since September 2023), this replaces user-not-found and wrong-password to prevent revealing whether an account exists. On the Firebase emulator, the code may appear as INVALID_LOGIN_CREDENTIALS.
  • operation-not-allowed:
  • Thrown if email/password accounts are not enabled. Enable email/password accounts in the Firebase Console, under the Auth tab.

Implementation

Future<UserCredential> signInWithEmailAndPassword({
  required String email,
  required String password,
}) async {
  try {
    return UserCredential._(
      this,
      await _delegate.signInWithEmailAndPassword(email, password),
    );
  } on FirebaseAuthMultiFactorExceptionPlatform catch (e) {
    throw FirebaseAuthMultiFactorException._(this, e);
  } catch (e) {
    rethrow;
  }
}