findSessions method

Future<List<AuthSessionInfo>> findSessions(
  1. Session session, {
  2. UuidValue? authUserId,
  3. String? method,
  4. Transaction? transaction,
})

List all sessions matching the given filters.

Implementation

Future<List<AuthSessionInfo>> findSessions(
  final Session session, {
  final UuidValue? authUserId,
  final String? method,
  final Transaction? transaction,
}) async {
  final authSessions = await AuthSession.db.find(
    session,
    where: (final t) {
      Expression<dynamic> expression = Constant.bool(true);

      if (authUserId != null) {
        expression &= t.authUserId.equals(authUserId);
      }

      if (method != null) {
        expression &= t.method.equals(method);
      }

      return expression;
    },
    transaction: transaction,
  );

  final sessionInfos = <AuthSessionInfo>[
    for (final authSession in authSessions)
      AuthSessionInfo(
        id: authSession.id!,
        authUserId: authSession.authUserId,
        scopeNames: authSession.scopeNames,
        created: authSession.createdAt,
        lastUsed: authSession.lastUsedAt,
        expiresAt: authSession.expiresAt,
        expireAfterUnusedFor: authSession.expireAfterUnusedFor,
        method: authSession.method,
      ),
  ];

  return sessionInfos;
}