isTokenExpired property
Whether the access token has expired or is within 5 minutes of expiry.
The 5-minute buffer triggers proactive refresh before the hard expiry, preventing race conditions where the token expires between validation and the outgoing API call.
if (token.isTokenExpired && !token.isRefreshTokenExpired) {
await authService.refreshToken();
}
Implementation
bool get isTokenExpired {
final DateTime expirationDateTime = DateTime.fromMillisecondsSinceEpoch(expiresIn, isUtc: true);
final DateTime expirationWithBuffer = expirationDateTime.subtract(expiryBuffer);
return !DateTime.now().toUtc().isBefore(expirationWithBuffer);
}