isTokenExpired method

Future<bool> isTokenExpired({
  1. Duration buffer = const Duration(minutes: 1),
})

Check if the current token is expired or will expire soon Returns true if token is expired or will expire within the next minute

Implementation

Future<bool> isTokenExpired({Duration buffer = const Duration(minutes: 1)}) async {
  final expiresAt = await getTokenExpiresAt();
  if (expiresAt == null) {
    return true; // No expiration time means token is considered expired
  }

  try {
    final expirationDate = DateTime.parse(expiresAt);
    final now = DateTime.now();
    final expiresWithBuffer = expirationDate.subtract(buffer);

    return now.isAfter(expiresWithBuffer);
  } on Exception {
    // If we can't parse the expiration date, consider token expired
    return true;
  }
}