getSession method

Future<AuthUserSessionDto?> getSession(
  1. String userId, {
  2. String? mid,
  3. String? businessId,
})

Implementation

Future<AuthUserSessionDto?> getSession(
  String userId, {
  String? mid,
  String? businessId,
}) async {
  _ensureInitialised();

  if (_useMockData) {
    await Future.delayed(const Duration(milliseconds: 300));
    return AuthUserSessionDto.fromJson(_generateMockSession(userId));
  }
  var request = CreateSessionRequest(
    userId: userId,
    mid: mid,
    businessId: businessId,
  );

  try {
    final client = await _createClientWithAuthHeaders();
    final response = await client.get(
      url: '$_sessionServiceUrl/userSession/api/session/GetUserSession',
      requestData: request.toJson(),
      user: _user,
    );

    if (response?.statusCode == 200 && response?.data != null) {
      return AuthUserSessionDto.fromJson(response!.data);
    } else if (response?.statusCode == 404) {
      return null;
    } else {
      throw AuthException(
        AuthenticationErrorCodes.sessionGetFailed,
        cause: response?.data,
      );
    }
  } catch (e, s) {
    logger.error(
      this,
      'Exception while getting session',
      error: e,
      stackTrace: s,
    );
    rethrow;
  }
}