@iblai/web-utils 1.11.10 → 1.11.12

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.js CHANGED
@@ -1771,6 +1771,24 @@ async function preCacheMentorData(org, mentorId, userId, fetchMentorSettings, fe
1771
1771
  }
1772
1772
  }
1773
1773
 
1774
+ async function openExternalUrl(url) {
1775
+ if (!url || typeof window === "undefined")
1776
+ return;
1777
+ if (!isTauri()) {
1778
+ window.location.href = url;
1779
+ return;
1780
+ }
1781
+ try {
1782
+ const { invoke } = await import('@tauri-apps/api/core');
1783
+ await invoke("open_external_url", { url });
1784
+ }
1785
+ catch (error) {
1786
+ console.error("[openExternalUrl] Failed to open URL via Tauri host, falling back to navigation:", error);
1787
+ // Fallback to normal navigation if the native command is unavailable.
1788
+ window.location.href = url;
1789
+ }
1790
+ }
1791
+
1774
1792
  const useTenantMetadata = ({ org, spa, skip = false, }) => {
1775
1793
  const { data, isLoading, isError } = dataLayer.useGetTenantMetadataQuery([{ org }], {
1776
1794
  skip: skip || !org,
@@ -9182,22 +9200,22 @@ async function syncAuthToCookies(storageService) {
9182
9200
  function hasNonExpiredAuthToken() {
9183
9201
  const token = window.localStorage.getItem(LOCAL_STORAGE_KEYS.AUTH_TOKEN);
9184
9202
  if (!token) {
9185
- console.log('################### [hasNonExpiredAuthToken] axd token is not defined', token);
9203
+ console.log("################### [hasNonExpiredAuthToken] axd token is not defined", token);
9186
9204
  return false;
9187
9205
  }
9188
9206
  const tokenExpiry = window.localStorage.getItem(LOCAL_STORAGE_KEYS.TOKEN_EXPIRY);
9189
9207
  if (!tokenExpiry) {
9190
- console.log('################### [hasNonExpiredAuthToken] axd token expiry is not defined', tokenExpiry);
9208
+ console.log("################### [hasNonExpiredAuthToken] axd token expiry is not defined", tokenExpiry);
9191
9209
  return true;
9192
9210
  }
9193
9211
  const expiryDate = new Date(tokenExpiry);
9194
9212
  if (isNaN(expiryDate.getTime())) {
9195
- console.log('################### [hasNonExpiredAuthToken] axd token expiry date', expiryDate);
9213
+ console.log("################### [hasNonExpiredAuthToken] axd token expiry date", expiryDate);
9196
9214
  return false;
9197
9215
  }
9198
9216
  const currentDate = new Date();
9199
9217
  if (expiryDate <= currentDate) {
9200
- console.log('################### [hasNonExpiredAuthToken] axd token expiry date is less than current date ', expiryDate, currentDate);
9218
+ console.log("################### [hasNonExpiredAuthToken] axd token expiry date is less than current date ", expiryDate, currentDate);
9201
9219
  return false;
9202
9220
  }
9203
9221
  return true;
@@ -9460,6 +9478,20 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
9460
9478
  console.log("[AuthProvider] Redirect already in progress, skipping");
9461
9479
  return;
9462
9480
  }
9481
+ // Defer every auth redirect while a tenant switch is in flight.
9482
+ // handleTenantSwitch() clears the SHARED (cross-tab) localStorage mid-switch,
9483
+ // so every open window transiently sees missing tokens. Without this guard a
9484
+ // bystander window force-logs-out on the absent DM token, which clears
9485
+ // storage + sets a logout-timestamp cookie that wipes the tokens the
9486
+ // switching tab just wrote and cascades the logout across tabs. The TTL lock
9487
+ // (writeTenantSwitchLock) survives the /login/complete -> /sso-login-complete
9488
+ // redirect and is kept fresh across tabs via useTenantSwitchSync, so it
9489
+ // brackets the switch window. The cross-SPA cookie-sync poll keeps running
9490
+ // and recovers once the new tenant's tokens land.
9491
+ if (isTenantSwitchInProgress()) {
9492
+ console.log("[AuthProvider] Tenant switch in progress, deferring auth redirect");
9493
+ return;
9494
+ }
9463
9495
  isRedirectingRef.current = true;
9464
9496
  redirectStartedAtRef.current = Date.now();
9465
9497
  // NOTE: we intentionally do NOT clear the interval here.
@@ -9645,6 +9677,17 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
9645
9677
  var _a;
9646
9678
  try {
9647
9679
  setIsAuthenticating(true);
9680
+ // During an in-flight tenant switch the shared, cross-tab localStorage is
9681
+ // transiently cleared (see handleTenantSwitch), so the auth/DM tokens are
9682
+ // legitimately absent. Bail out BEFORE onAuthFailure — some apps hard
9683
+ // navigate to /error/403 from that callback (e.g. skills does
9684
+ // `window.location.href = '/error/403'`), which would fire even though
9685
+ // safeRedirectToAuthSpa itself is guarded. The cookie-sync poll re-checks
9686
+ // once the new tenant's tokens land.
9687
+ if (isTenantSwitchInProgress()) {
9688
+ console.log("[AuthProvider] Tenant switch in progress, skipping auth check");
9689
+ return;
9690
+ }
9648
9691
  const authToken = await (storageService === null || storageService === void 0 ? void 0 : storageService.getItem(LOCAL_STORAGE_KEYS.AUTH_TOKEN));
9649
9692
  if (authToken && !hasNonExpiredAuthToken()) {
9650
9693
  const reason = "Auth token expired";
@@ -15018,7 +15061,7 @@ const useStripeUpgrade = ({ redirectUrl, sourcePlatformKey, mainPlatformKey, cur
15018
15061
  return;
15019
15062
  const target = redirectPlan === "free" ? resolvedFreeUrl : resolvedPremiumUrl;
15020
15063
  if (target) {
15021
- window.location.href = target;
15064
+ await openExternalUrl(target);
15022
15065
  }
15023
15066
  }
15024
15067
  catch (_a) {
@@ -19049,6 +19092,7 @@ exports.markdownToPlainText = markdownToPlainText;
19049
19092
  exports.monetizationSlice = monetizationSlice;
19050
19093
  exports.onStatusChange = onStatusChange;
19051
19094
  exports.onUpdate = onUpdate;
19095
+ exports.openExternalUrl = openExternalUrl;
19052
19096
  exports.parseCSV = parseCSV;
19053
19097
  exports.preCacheMentorData = preCacheMentorData;
19054
19098
  exports.rbacReducer = rbacReducer;