getSession method

Future<Session?> getSession({
  1. required ApiClient apiClient,
  2. bool forceRefresh = false,
})

Implementation

Future<Session?> getSession({
  required ApiClient apiClient,
  bool forceRefresh = false,
}) async {
  var session = _session;
  if (session == null) {
    return null;
  }

  if (!forceRefresh && !_hasExpired(session.expiresAt)) {
    return session;
  }

  session = await apiClient.refreshToken(
    sessionId: session.id,
    refreshToken: session.refreshToken,
  );

  await _writeSession(session);

  _session = session;

  return session;
}