init static method

void init(
  1. {required String apiDomain,
  2. String? apiBasePath,
  3. int? maxRetryAttemptsForSessionRefresh,
  4. int sessionExpiredStatusCode = 401,
  5. String? sessionTokenBackendDomain,
  6. SuperTokensTokenTransferMethod? tokenTransferMethod,
  7. dynamic eventHandler(
    1. Eventype
    )?,
  8. dynamic preAPIHook(
    1. APIAction,
    2. dynamic
    )?,
  9. dynamic postAPIHook(
    1. APIAction,
    2. dynamic,
    3. dynamic
    )?,
  10. bool? enableDebugLogs}
)

Implementation

static void init({
  required String apiDomain,
  String? apiBasePath,
  int? maxRetryAttemptsForSessionRefresh,
  int sessionExpiredStatusCode = 401,
  String? sessionTokenBackendDomain,
  SuperTokensTokenTransferMethod? tokenTransferMethod,
  Function(Eventype)? eventHandler,
  http.Request Function(APIAction, http.Request)? preAPIHook,
  Function(APIAction, http.Request, http.Response)? postAPIHook,
  bool? enableDebugLogs,
}) {
  if (SuperTokens.isInitCalled) {
    return;
  }

  // Enable debug mode if that is specified by the user.
  if (enableDebugLogs != null && enableDebugLogs) {
    enableLogging();
  }

  logDebugMessage("SuperTokens.init: Started SuperTokens with debug logging (supertokens.init called)");

  SuperTokens.config = NormalisedInputType.normaliseInputType(
    apiDomain,
    apiBasePath,
    sessionExpiredStatusCode,
    maxRetryAttemptsForSessionRefresh,
    sessionTokenBackendDomain,
    tokenTransferMethod,
    eventHandler,
    preAPIHook,
    postAPIHook,
  );

  logDebugMessage('SuperTokens.init: config: ${jsonEncode(config.toJson())}');

  SuperTokens.refreshTokenUrl =
      config.apiDomain + (config.apiBasePath ?? '') + "/session/refresh";
  SuperTokens.signOutUrl =
      config.apiDomain + (config.apiBasePath ?? '') + "/signout";
  SuperTokens.rid = "session";

  logDebugMessage('SuperTokens.init: refreshTokenUrl: ${refreshTokenUrl}');
  logDebugMessage('SuperTokens.init: signOutUrl: ${signOutUrl}');
  logDebugMessage('SuperTokens.init: rid: ${rid}');

  SuperTokens.isInitCalled = true;
}