list method

Future<List<DVSession>> list(
  1. String userId, {
  2. String? currentToken,
})

Every live session of userId, newest sign-in first, with the one currentToken authenticates marked current.

Implementation

Future<List<DVSession>> list(String userId, {String? currentToken}) async {
  final DateTime now = _now;
  final String? currentHash =
      currentToken == null ? null : _hash(currentToken);
  final List<DVSessionRecord> records = await store.forUser(userId);
  final List<DVSession> live = <DVSession>[
    for (final DVSessionRecord record in records)
      if (record.session.revokedAt == null && !_expired(record.session, now))
        record.session._copy(
          isCurrent: currentHash != null &&
              _sameHash(record.tokenHash, currentHash),
        ),
  ]..sort((DVSession a, DVSession b) => b.createdAt.compareTo(a.createdAt));
  return live;
}