attemptRefreshingSession static method

Future<bool> attemptRefreshingSession()

Implementation

static Future<bool> attemptRefreshingSession() async {
  logDebugMessage('SuperTokens.attemptRefreshingSession: Attempting to refresh session');
  LocalSessionState preRequestLocalSessionState =
      await SuperTokensUtils.getLocalSessionState();
  bool shouldRetry = false;
  Exception? exception;

  dynamic resp =
      await Client.onUnauthorisedResponse(preRequestLocalSessionState);
  if (resp is UnauthorisedResponse) {
    logDebugMessage('SuperTokens.attemptRefreshingSession: Got unauthorised response');
    if (resp.status == UnauthorisedStatus.API_ERROR) {
      logDebugMessage('SuperTokens.attemptRefreshingSession: Got API error');
      exception = resp.error as SuperTokensException;
    } else {
      shouldRetry = resp.status == UnauthorisedStatus.RETRY;
      logDebugMessage('SuperTokens.attemptRefreshingSession: shouldRetry: ${shouldRetry}');
    }
  }
  if (exception != null) {
    throw exception;
  }
  return shouldRetry;
}