signInWithCustomToken method Null safety

Future<UserCredential> signInWithCustomToken(
  1. String token

Tries to sign in a user with a given custom token.

Custom tokens are used to integrate Firebase Auth with existing auth systems, and must be generated by the auth backend.

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

If the user identified by the uid specified in the token doesn't have an account already, one will be created automatically.

Read how to use Custom Token authentication and the cases where it is useful in the guides.

A FirebaseAuthException maybe thrown with the following error code:

  • custom-token-mismatch:
  • Thrown if the custom token is for a different Firebase App.
  • invalid-custom-token:
  • Thrown if the custom token format is incorrect.


Future<UserCredential> signInWithCustomToken(String token) async {
  try {
    return UserCredential._(
        this, await _delegate.signInWithCustomToken(token));
  } on FirebaseAuthMultiFactorExceptionPlatform catch (e) {
    throw FirebaseAuthMultiFactorException._(this, e);
  } catch (e) {