clearOutdated method

  1. @override
Future<void> clearOutdated()
override

Implementation

@override
Future<void> clearOutdated() async {
  final now = DateTime.now();
  final results = await sqlSelect("SELECT * FROM $tableName");
  if (results == null || results.isEmpty) {
    return;
  }
  final List<Future<void>> deletions = [];

  for (var result in results) {
    final secretBox = SecretBox(
      base64.decode(result['cipherText'] as String),
      nonce: base64.decode(result['nonce'] as String),
      mac: Mac(base64.decode(result['mac'] as String)),
    );
    final clearText = await algorithm.decryptString(
      secretBox,
      secretKey: secretKey,
    );
    final session = Session.fromJson(clearText);
    if (session.expires.compareTo(now) < 0) {
      deletions.add(deleteSession(session.id));
    }
  }

  await Future.wait(deletions);
}