@iblai/web-utils 1.2.6 → 1.2.8

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
@@ -2842,12 +2842,22 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2842
2842
  return;
2843
2843
  }
2844
2844
  isRedirectingRef.current = true;
2845
- // Stop polling immediately to prevent stale callbacks
2846
- if (cookieCheckIntervalRef.current) {
2847
- clearInterval(cookieCheckIntervalRef.current);
2848
- cookieCheckIntervalRef.current = null;
2849
- }
2845
+ // NOTE: we intentionally do NOT clear the interval here.
2846
+ // The isRedirectingRef guard prevents redundant redirects while navigation
2847
+ // is in progress. Clearing the interval preemptively can permanently stop
2848
+ // cross-SPA sync if the consuming app suppresses the redirect (e.g. during
2849
+ // its own concurrent tenant switch), leaving the page with no active poller.
2850
2850
  redirectToAuthSpa(...args);
2851
+ // Safety recovery: if navigation was suppressed by the consuming app
2852
+ // (e.g. _suppressAuthRedirect was true), reset the guard after a short delay
2853
+ // so the interval can resume cross-SPA sync on its next tick.
2854
+ // If navigation did occur, the page will have unloaded before this fires.
2855
+ setTimeout(() => {
2856
+ if (isRedirectingRef.current) {
2857
+ console.log("[AuthProvider] safeRedirectToAuthSpa: navigation did not occur, resetting redirect guard");
2858
+ isRedirectingRef.current = false;
2859
+ }
2860
+ }, 3000);
2851
2861
  };
2852
2862
  /**
2853
2863
  * Sync cookies to localStorage on mount and periodically (web only)
@@ -2856,6 +2866,11 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2856
2866
  * Skipped if enableStorageSync is false
2857
2867
  */
2858
2868
  React.useEffect(() => {
2869
+ console.log("[AuthProvider] cookie-sync effect running", {
2870
+ pathname,
2871
+ enableStorageSync,
2872
+ hasStorageService: !!storageService,
2873
+ });
2859
2874
  if (!storageService || !isWeb$1() || !enableStorageSync) {
2860
2875
  // If no storage service, not web, or sync disabled, mark sync as complete immediately
2861
2876
  setInitialSyncComplete(true);
@@ -2865,16 +2880,22 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2865
2880
  isRedirectingRef.current = false;
2866
2881
  // Initial sync on mount
2867
2882
  async function initialSync() {
2883
+ console.log("[AuthProvider] initialSync starting");
2868
2884
  try {
2869
2885
  // Initialize last known logout timestamp
2870
2886
  lastLogoutTimestampRef.current = CookieUtils.get(COOKIE_KEYS.LOGOUT_TIMESTAMP);
2871
2887
  const { needsRefresh, userDataOutOfSync } = await syncCookiesToLocalStorage(storageService);
2888
+ console.log("[AuthProvider] initialSync result", {
2889
+ needsRefresh,
2890
+ userDataOutOfSync,
2891
+ });
2872
2892
  if (needsRefresh) {
2873
2893
  console.log("[auth-redirect] Cookie sync detected changes, refreshing page");
2874
2894
  // If user data is out of sync, trigger logout to force re-authentication
2875
2895
  safeRedirectToAuthSpa(undefined, undefined, userDataOutOfSync, false);
2876
2896
  }
2877
2897
  else {
2898
+ console.log("[AuthProvider] initialSync no changes, syncing auth to cookies");
2878
2899
  await syncAuthToCookies(storageService);
2879
2900
  }
2880
2901
  }
@@ -2887,8 +2908,10 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2887
2908
  // Poll for cookie changes every 2 seconds to detect cross-SPA updates
2888
2909
  cookieCheckIntervalRef.current = setInterval(async () => {
2889
2910
  // If a redirect is already in progress, skip entirely
2890
- if (isRedirectingRef.current)
2911
+ if (isRedirectingRef.current) {
2912
+ console.log("[AuthProvider] interval: redirect already in progress, skipping");
2891
2913
  return;
2914
+ }
2892
2915
  // Skip cookie sync checks if user is completing SSO at /sso-login
2893
2916
  const completingSso = /^\/sso-login/.test(pathname);
2894
2917
  if (completingSso) {
@@ -2909,6 +2932,11 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2909
2932
  return;
2910
2933
  }
2911
2934
  const { needsRefresh, userDataOutOfSync } = await syncCookiesToLocalStorage(storageService);
2935
+ console.log("[AuthProvider] interval poll result", {
2936
+ needsRefresh,
2937
+ userDataOutOfSync,
2938
+ pathname,
2939
+ });
2912
2940
  if (needsRefresh) {
2913
2941
  console.log("[auth-redirect] Cookie sync detected changes from another SPA, refreshing page");
2914
2942
  let cookieTenantKey;
@@ -2917,6 +2945,10 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2917
2945
  cookieTenantKey = cookieCurrentTenant.key;
2918
2946
  }
2919
2947
  catch (_a) { }
2948
+ console.log("[AuthProvider] interval redirecting to auth spa", {
2949
+ cookieTenantKey,
2950
+ userDataOutOfSync,
2951
+ });
2920
2952
  // If user data is out of sync, trigger logout to force re-authentication
2921
2953
  safeRedirectToAuthSpa(undefined, cookieTenantKey, userDataOutOfSync, false);
2922
2954
  }
@@ -2926,6 +2958,7 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2926
2958
  }, 2000);
2927
2959
  // Cleanup interval on unmount
2928
2960
  return () => {
2961
+ console.log("[AuthProvider] cookie-sync effect cleanup", { pathname });
2929
2962
  if (cookieCheckIntervalRef.current) {
2930
2963
  clearInterval(cookieCheckIntervalRef.current);
2931
2964
  }
@@ -5901,6 +5934,7 @@ const initialState$3 = {
5901
5934
  href: "",
5902
5935
  },
5903
5936
  pageContent: "",
5937
+ metadata: null,
5904
5938
  },
5905
5939
  documentFilter: null,
5906
5940
  token: null,
@@ -8044,6 +8078,7 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
8044
8078
  messageData = {
8045
8079
  ...messageData,
8046
8080
  page_content: iframeContext.pageContent,
8081
+ metadata: iframeContext.metadata,
8047
8082
  };
8048
8083
  }
8049
8084
  if (documentFilter) {