whenAccessTokenExpired method

void whenAccessTokenExpired(
  1. String accessToken,
  2. DateTime expiresAt,
  3. WithNewAccessToken withNewAccessToken
)

Sets up a periodic check for the expiration of the accessToken. Once expired, it attempts to get a new token by calling getNewAccessToken. The withNewAccessToken function is called when a new token is obtained.

Implementation

void whenAccessTokenExpired(String accessToken, DateTime expiresAt,
    WithNewAccessToken withNewAccessToken) {
  expiration = expiresAt;
  periodicTimer = Timer.periodic(
    const Duration(hours: 1),
    (timer) async {
      if (isAccessTokenExpired(const Duration(hours: 1))) {
        if (token != null) {
          await getNewAccessToken(token!);
        }
      }
    },
  );
}