thisSession property

Session? get thisSession

Returns the current guest session associated with the request.

This getter looks for the archery_guest_session cookie, resolves the matching session from the in-memory session registry, updates the session's lastActivity timestamp, and returns it.

Returns null when no matching session can be found or resolution fails.

Example:

final session = request.thisSession;
  if (session != null) {
    print('Guest session active');
  }

Implementation

Session? get thisSession {
  try {
    final cookie = cookies.firstWhereOrNull((cookie) => cookie.name == "archery_guest_session");
    final sessions = App().tryMake<List<Session>>();
    if (cookie != null) {
      final session = sessions?.firstWhereOrNull((session) => session.token == cookie.value);
      if (session != null) {
        session.lastActivity = DateTime.now();
        return session;
      }
    }
    return null;
  } catch (e) {
    return null;
  }
}