@iblai/web-utils 1.5.0 → 1.6.1
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 +3 -3
- package/dist/index.esm.js +16 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +16 -9
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/web-utils/src/providers/auth-provider.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2527,6 +2527,7 @@ const COOKIE_KEYS = {
|
|
|
2527
2527
|
USER_DATA: "ibl_user_data",
|
|
2528
2528
|
TENANT: "ibl_tenant",
|
|
2529
2529
|
LOGOUT_TIMESTAMP: "ibl_logout_timestamp",
|
|
2530
|
+
LOGIN_TIMESTAMP: "ibl_login_timestamp",
|
|
2530
2531
|
};
|
|
2531
2532
|
/**
|
|
2532
2533
|
* Get the base domain for cookie sharing
|
|
@@ -2838,6 +2839,7 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
|
|
|
2838
2839
|
const [initialSyncComplete, setInitialSyncComplete] = React.useState(false);
|
|
2839
2840
|
const cookieCheckIntervalRef = React.useRef(null);
|
|
2840
2841
|
const lastLogoutTimestampRef = React.useRef(null);
|
|
2842
|
+
const lastLoginTimestampRef = React.useRef(null);
|
|
2841
2843
|
// Guard to prevent poll from firing after a redirect has been initiated.
|
|
2842
2844
|
// Once set, no further redirects or cookie syncs will happen.
|
|
2843
2845
|
const isRedirectingRef = React.useRef(false);
|
|
@@ -2852,11 +2854,6 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
|
|
|
2852
2854
|
console.log("[AuthProvider] Redirect already in progress, skipping");
|
|
2853
2855
|
return;
|
|
2854
2856
|
}
|
|
2855
|
-
// Skip if a tenant switch is already in progress
|
|
2856
|
-
if (isWeb$1() && document.cookie.includes("ibl_tenant_switching")) {
|
|
2857
|
-
console.log("[AuthProvider] Tenant switch in progress, skipping redirect");
|
|
2858
|
-
return;
|
|
2859
|
-
}
|
|
2860
2857
|
isRedirectingRef.current = true;
|
|
2861
2858
|
// NOTE: we intentionally do NOT clear the interval here.
|
|
2862
2859
|
// The isRedirectingRef guard prevents redundant redirects while navigation
|
|
@@ -2882,6 +2879,10 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
|
|
|
2882
2879
|
* Skipped if enableStorageSync is false
|
|
2883
2880
|
*/
|
|
2884
2881
|
React.useEffect(() => {
|
|
2882
|
+
if (skipAuthCheck) {
|
|
2883
|
+
setInitialSyncComplete(true);
|
|
2884
|
+
return;
|
|
2885
|
+
}
|
|
2885
2886
|
console.log("[AuthProvider] cookie-sync effect running", {
|
|
2886
2887
|
pathname,
|
|
2887
2888
|
enableStorageSync,
|
|
@@ -2898,8 +2899,9 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
|
|
|
2898
2899
|
async function initialSync() {
|
|
2899
2900
|
console.log("[AuthProvider] initialSync starting");
|
|
2900
2901
|
try {
|
|
2901
|
-
// Initialize last known logout
|
|
2902
|
+
// Initialize last known logout and login timestamps
|
|
2902
2903
|
lastLogoutTimestampRef.current = CookieUtils.get(COOKIE_KEYS.LOGOUT_TIMESTAMP);
|
|
2904
|
+
lastLoginTimestampRef.current = CookieUtils.get(COOKIE_KEYS.LOGIN_TIMESTAMP);
|
|
2903
2905
|
const { needsRefresh, userDataOutOfSync } = await syncCookiesToLocalStorage(storageService);
|
|
2904
2906
|
console.log("[AuthProvider] initialSync result", {
|
|
2905
2907
|
needsRefresh,
|
|
@@ -2989,7 +2991,7 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
|
|
|
2989
2991
|
* Skipped if enableStorageSync is false
|
|
2990
2992
|
*/
|
|
2991
2993
|
React.useEffect(() => {
|
|
2992
|
-
if (!storageService || !isWeb$1() || !enableStorageSync)
|
|
2994
|
+
if (!storageService || !isWeb$1() || !enableStorageSync || skipAuthCheck)
|
|
2993
2995
|
return;
|
|
2994
2996
|
const handleStorageChange = async (event) => {
|
|
2995
2997
|
// Only handle changes to our auth-related keys
|
|
@@ -3089,6 +3091,11 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
|
|
|
3089
3091
|
}
|
|
3090
3092
|
}
|
|
3091
3093
|
React.useEffect(() => {
|
|
3094
|
+
if (skipAuthCheck) {
|
|
3095
|
+
setIsAuthenticating(false);
|
|
3096
|
+
setUserIsAccessingPublicRoute(true);
|
|
3097
|
+
return;
|
|
3098
|
+
}
|
|
3092
3099
|
// Wait for initial sync to complete before performing auth check
|
|
3093
3100
|
if (!initialSyncComplete) {
|
|
3094
3101
|
console.log("[useAuthProvider] Waiting for initial sync to complete...");
|
|
@@ -3166,7 +3173,7 @@ async function determineAuthRequired(middleware, pathname) {
|
|
|
3166
3173
|
* 4. Handles redirects to auth SPA when needed
|
|
3167
3174
|
* 5. Manages public route access state
|
|
3168
3175
|
*/
|
|
3169
|
-
function AuthProvider({ children, fallback, middleware = new Map(), onAuthSuccess, onAuthFailure, redirectToAuthSpa, hasNonExpiredAuthToken, username, pathname,
|
|
3176
|
+
function AuthProvider({ children, fallback, middleware = new Map(), onAuthSuccess, onAuthFailure, redirectToAuthSpa, hasNonExpiredAuthToken, username, pathname, storageService, token, enableStorageSync = true, skip = false, }) {
|
|
3170
3177
|
const { isAuthenticating, userIsAccessingPublicRoute, setUserIsAccessingPublicRoute, } = useAuthProvider({
|
|
3171
3178
|
middleware,
|
|
3172
3179
|
onAuthSuccess,
|
|
@@ -3176,7 +3183,7 @@ function AuthProvider({ children, fallback, middleware = new Map(), onAuthSucces
|
|
|
3176
3183
|
username,
|
|
3177
3184
|
pathname,
|
|
3178
3185
|
storageService,
|
|
3179
|
-
|
|
3186
|
+
skip,
|
|
3180
3187
|
token,
|
|
3181
3188
|
enableStorageSync,
|
|
3182
3189
|
});
|