authenticate abstract method

Future<AuthResponse> authenticate({
  1. required String username,
  2. required String password,
})

Authenticate the user using the user information provided as an argument.

The username argument should not only be a username, but also an email address that has already been authenticated by Duolingo.

If a user who has already been authenticated tries to authenticate again, the API will return an invalid password error.

When the user associated with username and password is authenticated, there is no need to call cleanCache or any other method to delete the cache when the user is authenticated. The cache information will be cleaned automatically.

Example:

void main() async {
  final duolingo = Duolingo.instance;

  final authResponse = await duolingo.authenticate(
    username: 'test_username',
    password: 'test_password',
  );

  if (authResponse.status.isNotOk) {
    authResponse.status.reasonPhrase;
    authResponse.headers;
    return;
  }

  if (authResponse.hasError) {
    final authError = authResponse.error!;
    print(authError.code);
    print(authError.reason);

    authError.isInvalidUser;
    authError.isInvalidPassword;
    return;
  }
}

Implementation

Future<AuthResponse> authenticate({
  required String username,
  required String password,
});