checkAuthentication method

Future<void> checkAuthentication()

Checks the authentication status and performs actions depending on the status

If the User is not authenticated and ActiveGridAuthenticationOptions.autoAuthenticate is true this will call authenticate

If the token is expired it will refresh the token using the refresh token

Implementation

Future<void> checkAuthentication() async {
  if (_token == null &&
      options.authenticationOptions?.autoAuthenticate == true) {
    await authenticate();
  }

  if (_token != null && _token?.expiresIn?.isNegative == true) {
    // Token is expired refresh it
    final client = await _client;
    client.createCredential(refreshToken: _token?.refreshToken);
    final authenticator =
        testAuthenticator ?? Authenticator(client, urlLauncher: (_) {});
    final credential = await authenticator.authorize();

    _token = await credential?.getTokenResponse();
  }
}