signInWithCredential method Null safety

Future<UserCredential> signInWithCredential(
  1. AuthCredential credential
)

Asynchronously signs in to Firebase with the given 3rd-party credentials (e.g. a Facebook login Access Token, a Google ID Token/Access Token pair, etc.) and returns additional identity provider data.

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

If the user doesn't have an account already, one will be created automatically.

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

A FirebaseAuthException maybe thrown with the following error code:

  • account-exists-with-different-credential:
  • Thrown if there already exists an account with the email address asserted by the credential. Resolve this by calling fetchSignInMethodsForEmail and then asking the user to sign in using one of the returned providers. Once the user is signed in, the original credential can be linked to the user with linkWithCredential.
  • invalid-credential:
  • Thrown if the credential is malformed or has expired.
  • operation-not-allowed:
  • Thrown if the type of account corresponding to the credential is not enabled. Enable the account type in the Firebase Console, under the Auth tab.
  • user-disabled:
  • Thrown if the user corresponding to the given credential has been disabled.
  • user-not-found:
  • Thrown if signing in with a credential from EmailAuthProvider.credential and there is no user corresponding to the given email.
  • wrong-password:
  • Thrown if signing in with a credential from EmailAuthProvider.credential and the password is invalid for the given email, or if the account corresponding to the email does not have a password set.
  • invalid-verification-code:
  • Thrown if the credential is a PhoneAuthProvider.credential and the verification code of the credential is not valid.
  • invalid-verification-id:
  • Thrown if the credential is a PhoneAuthProvider.credential and the verification ID of the credential is not valid.id.

Implementation

Future<UserCredential> signInWithCredential(AuthCredential credential) async {
  return UserCredential._(
    this,
    await _delegate.signInWithCredential(credential),
  );
}