@torq-north/react-tools 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -144,8 +144,12 @@ var sendGet = function (url, params) { return __awaiter(void 0, void 0, void 0,
144
144
  switch (_a.label) {
145
145
  case 0:
146
146
  params &&
147
- Object.keys(params).forEach(function (key) { return params[key] === undefined && delete params[key]; });
148
- fetchUrl = params ? "".concat(url, "?").concat(new URLSearchParams(params).toString()) : url;
147
+ Object.keys(params).forEach(function (key) {
148
+ return params[key] === undefined && delete params[key];
149
+ });
150
+ fetchUrl = params
151
+ ? "".concat(url, "?").concat(new URLSearchParams(params).toString())
152
+ : url;
149
153
  return [4 /*yield*/, fetch(fetchUrl)];
150
154
  case 1:
151
155
  response = _a.sent();
@@ -246,11 +250,29 @@ function isJson(response) {
246
250
  }
247
251
  return contentType.indexOf("application/json") >= 0;
248
252
  }
253
+ var authLoginUrl = "/auth/login";
254
+ var authRedirectEnabled = false;
255
+ function enableAuthRedirect(loginUrl) {
256
+ if (loginUrl === void 0) { loginUrl = "/auth/login"; }
257
+ authLoginUrl = loginUrl;
258
+ authRedirectEnabled = true;
259
+ }
260
+ function isSessionExpired(response) {
261
+ return (response.status === 401 ||
262
+ (response.redirected && response.url.includes("/auth/login")));
263
+ }
249
264
  function process$1(response) {
250
265
  return __awaiter(this, void 0, void 0, function () {
251
266
  return __generator(this, function (_a) {
252
267
  switch (_a.label) {
253
- case 0: return [4 /*yield*/, checkResponse(response)];
268
+ case 0:
269
+ if (authRedirectEnabled && isSessionExpired(response)) {
270
+ window.location.href = authLoginUrl;
271
+ // Return a never-resolving promise to suspend execution while the browser navigates away,
272
+ // preventing any error handling or UI updates from firing before the page unloads.
273
+ return [2 /*return*/, new Promise(function () { })];
274
+ }
275
+ return [4 /*yield*/, checkResponse(response)];
254
276
  case 1:
255
277
  _a.sent();
256
278
  if (isJson(response)) {
@@ -5176,5 +5198,5 @@ function TabSet(_a) {
5176
5198
  }) }) }), jsx(Panel, __assign({}, actualTab === null || actualTab === void 0 ? void 0 : actualTab.PanelProps, { children: actualTab === null || actualTab === void 0 ? void 0 : actualTab.content }))] }));
5177
5199
  }
5178
5200
 
5179
- export { CheckboxFormField, CloseableDialog, ConfirmCancel, DateFormField, DateTimeFormField, EMAIL_REGEX, EditableBlock, ErrorMessage, ErrorNotification, ErrorOverlay, ExtendedPagination, ExtendedTable, FieldWrapper, FileDisplay, FileDropper, FileEditorField, LabeledValue, LoaderButton, MultiSelectFormField, POSTAL_CODE_REGEX, Panel, RadioFormField, SelectFormField, TabSet, TextFormField, asInteger, asPhoneNumber, isEmail, isPostalCode, sendDelete, sendFormDataPost, sendGet, sendPost, sendPut, useAsyncData, useAsyncDataCallback, useDebounce, useDebounceEffect, usePartialSetterState };
5201
+ export { CheckboxFormField, CloseableDialog, ConfirmCancel, DateFormField, DateTimeFormField, EMAIL_REGEX, EditableBlock, ErrorMessage, ErrorNotification, ErrorOverlay, ExtendedPagination, ExtendedTable, FieldWrapper, FileDisplay, FileDropper, FileEditorField, LabeledValue, LoaderButton, MultiSelectFormField, POSTAL_CODE_REGEX, Panel, RadioFormField, SelectFormField, TabSet, TextFormField, asInteger, asPhoneNumber, enableAuthRedirect, isEmail, isPostalCode, sendDelete, sendFormDataPost, sendGet, sendPost, sendPut, useAsyncData, useAsyncDataCallback, useDebounce, useDebounceEffect, usePartialSetterState };
5180
5202
  //# sourceMappingURL=index.es.js.map