@iblai/web-utils 1.4.1 → 1.6.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.d.ts CHANGED
@@ -1642,6 +1642,7 @@ type Props = {
1642
1642
  skip?: boolean;
1643
1643
  onLoadPlatformPermissions?: (rbacPermissions: Record<string, unknown> | undefined) => void;
1644
1644
  skipCustomDomainCheck?: boolean;
1645
+ onTenantMismatch?: () => void;
1645
1646
  };
1646
1647
  /**
1647
1648
  * TenantProvider Component
@@ -1653,7 +1654,7 @@ type Props = {
1653
1654
  * 4. Handles tenant-specific domain redirects
1654
1655
  * 5. Maintains tenant access state
1655
1656
  */
1656
- declare function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, currentTenant, requestedTenant, saveCurrentTenant, saveUserTenants, handleTenantSwitch, saveVisitingTenant, removeVisitingTenant, saveUserTokens, saveTenant, onAutoJoinUserToTenant, redirectToAuthSpa, username, isIframed, setUseMentorProvider, skip, onLoadPlatformPermissions, skipCustomDomainCheck, }: Props): string | number | bigint | boolean | Iterable<React__default.ReactNode> | Promise<string | number | bigint | boolean | React__default.ReactPortal | React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>> | Iterable<React__default.ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null | undefined;
1657
+ declare function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, currentTenant, requestedTenant, saveCurrentTenant, saveUserTenants, handleTenantSwitch, saveVisitingTenant, removeVisitingTenant, saveUserTokens, saveTenant, onAutoJoinUserToTenant, redirectToAuthSpa, username, isIframed, setUseMentorProvider, skip, onLoadPlatformPermissions, skipCustomDomainCheck, onTenantMismatch, }: Props): string | number | bigint | boolean | Iterable<React__default.ReactNode> | Promise<string | number | bigint | boolean | React__default.ReactPortal | React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>> | Iterable<React__default.ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null | undefined;
1657
1658
 
1658
1659
  /**
1659
1660
  * Chat area size constants
package/dist/index.esm.js CHANGED
@@ -2507,6 +2507,7 @@ const COOKIE_KEYS = {
2507
2507
  USER_DATA: "ibl_user_data",
2508
2508
  TENANT: "ibl_tenant",
2509
2509
  LOGOUT_TIMESTAMP: "ibl_logout_timestamp",
2510
+ LOGIN_TIMESTAMP: "ibl_login_timestamp",
2510
2511
  };
2511
2512
  /**
2512
2513
  * Get the base domain for cookie sharing
@@ -2818,6 +2819,7 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2818
2819
  const [initialSyncComplete, setInitialSyncComplete] = useState(false);
2819
2820
  const cookieCheckIntervalRef = useRef(null);
2820
2821
  const lastLogoutTimestampRef = useRef(null);
2822
+ const lastLoginTimestampRef = useRef(null);
2821
2823
  // Guard to prevent poll from firing after a redirect has been initiated.
2822
2824
  // Once set, no further redirects or cookie syncs will happen.
2823
2825
  const isRedirectingRef = useRef(false);
@@ -2873,8 +2875,9 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2873
2875
  async function initialSync() {
2874
2876
  console.log("[AuthProvider] initialSync starting");
2875
2877
  try {
2876
- // Initialize last known logout timestamp
2878
+ // Initialize last known logout and login timestamps
2877
2879
  lastLogoutTimestampRef.current = CookieUtils.get(COOKIE_KEYS.LOGOUT_TIMESTAMP);
2880
+ lastLoginTimestampRef.current = CookieUtils.get(COOKIE_KEYS.LOGIN_TIMESTAMP);
2878
2881
  const { needsRefresh, userDataOutOfSync } = await syncCookiesToLocalStorage(storageService);
2879
2882
  console.log("[AuthProvider] initialSync result", {
2880
2883
  needsRefresh,
@@ -2927,6 +2930,8 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
2927
2930
  needsRefresh,
2928
2931
  userDataOutOfSync,
2929
2932
  pathname,
2933
+ currentLogoutTimestamp,
2934
+ lastLogoutTimestampRef: lastLogoutTimestampRef.current,
2930
2935
  });
2931
2936
  if (needsRefresh) {
2932
2937
  console.log("[auth-redirect] Cookie sync detected changes from another SPA, refreshing page");
@@ -3203,7 +3208,7 @@ const useTenantContext = () => useContext(TenantContext);
3203
3208
  * 4. Handles tenant-specific domain redirects
3204
3209
  * 5. Maintains tenant access state
3205
3210
  */
3206
- function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, currentTenant, requestedTenant, saveCurrentTenant, saveUserTenants, handleTenantSwitch, saveVisitingTenant, removeVisitingTenant, saveUserTokens, saveTenant, onAutoJoinUserToTenant, redirectToAuthSpa, username, isIframed = false, setUseMentorProvider, skip = false, onLoadPlatformPermissions, skipCustomDomainCheck = false, }) {
3211
+ function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, currentTenant, requestedTenant, saveCurrentTenant, saveUserTenants, handleTenantSwitch, saveVisitingTenant, removeVisitingTenant, saveUserTokens, saveTenant, onAutoJoinUserToTenant, redirectToAuthSpa, username, isIframed = false, setUseMentorProvider, skip = false, onLoadPlatformPermissions, skipCustomDomainCheck = false, onTenantMismatch = () => { }, }) {
3207
3212
  // If skip is true, just return children without any provider logic
3208
3213
  if (skip) {
3209
3214
  return jsx(Fragment, { children: children });
@@ -3634,6 +3639,30 @@ function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, curr
3634
3639
  isLoadingCustomDomain,
3635
3640
  isCustomDomainError,
3636
3641
  ]);
3642
+ // Poll every 2s: if requestedTenant exists, differs from currentTenant,
3643
+ // and user is not on a public route, invoke the onTenantMismatch callback.
3644
+ React__default.useEffect(() => {
3645
+ if (!onTenantMismatch)
3646
+ return;
3647
+ const interval = setInterval(() => {
3648
+ if (requestedTenant &&
3649
+ currentTenant &&
3650
+ requestedTenant !== currentTenant &&
3651
+ !userIsAccessingPublicRoute) {
3652
+ console.log("[TenantProvider] Tenant mismatch detected", {
3653
+ requestedTenant,
3654
+ currentTenant,
3655
+ });
3656
+ onTenantMismatch();
3657
+ }
3658
+ }, 2000);
3659
+ return () => clearInterval(interval);
3660
+ }, [
3661
+ requestedTenant,
3662
+ currentTenant,
3663
+ userIsAccessingPublicRoute,
3664
+ onTenantMismatch,
3665
+ ]);
3637
3666
  // Show fallback component during tenant determination
3638
3667
  if (isLoading) {
3639
3668
  return fallback;