tokenExpired method

  1. @override
Future<bool> tokenExpired()
override

Checks if the suer token is still expired.

Implementation

@override
Future<bool> tokenExpired() async {
  if (!_isAuthenticated || _instance == null) return true;

  try {
    // The authenticated client handles token refreshes automatically, but we can make a
    // lightweight call to check for connectivity and fundamental auth issues.
    await driveApi.about.get($fields: 'user');
    return false; // If the call succeeds, the token is considered valid.
  } on drive.DetailedApiRequestError catch (e) {
    if (e.status == 401 || e.status == 403) {
      _isAuthenticated = false; // Token is invalid or expired
      return true;
    }
    return false; // Some other API error
  } on http.ClientException catch (_) {
    // Likely a network issue, not an auth issue.
    return false;
  } catch (_) {
    // Unknown error, could be anything.
    return false;
  }
}