refreshSession method

Future<AuthUserSessionDto> refreshSession(
  1. UpdateSessionRequest request
)

Implementation

Future<AuthUserSessionDto> refreshSession(
  UpdateSessionRequest request,
) async {
  _ensureInitialised();

  /// Todo: see if this is still required?

  if (_useMockData) {
    await Future.delayed(const Duration(milliseconds: 500));
    return AuthUserSessionDto.fromJson(_generateMockSession(request.userId));
  }

  try {
    final client = await _createClientWithAuthHeaders();
    final response = await client.post(
      url: '$_sessionServiceUrl/Session/UpdateSession',
      requestData: request.toJson(),
      user: _user,
    );

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