@spidy092/auth-client 3.1.5 → 3.1.6

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.cjs CHANGED
@@ -1302,6 +1302,7 @@ function AuthProvider({ children, onSessionExpired, manageSessionSecurity = true
1302
1302
  const onSessionExpiredRef = (0, import_react.useRef)(onSessionExpired);
1303
1303
  const recoveryInFlightRef = (0, import_react.useRef)(null);
1304
1304
  const profileRecoveryTokensRef = (0, import_react.useRef)(/* @__PURE__ */ new Set());
1305
+ const profileLoadedRef = (0, import_react.useRef)(false);
1305
1306
  (0, import_react.useEffect)(() => {
1306
1307
  onSessionExpiredRef.current = onSessionExpired;
1307
1308
  }, [onSessionExpired]);
@@ -1311,8 +1312,9 @@ function AuthProvider({ children, onSessionExpired, manageSessionSecurity = true
1311
1312
  setTokenState(nextToken);
1312
1313
  if (nextToken) {
1313
1314
  setSessionValid(true);
1314
- setLoading(true);
1315
+ if (!profileLoadedRef.current) setLoading(true);
1315
1316
  } else {
1317
+ profileLoadedRef.current = false;
1316
1318
  setSessionValid(false);
1317
1319
  setUser(null);
1318
1320
  setLoading(false);
@@ -1324,6 +1326,7 @@ function AuthProvider({ children, onSessionExpired, manageSessionSecurity = true
1324
1326
  clearToken();
1325
1327
  setTokenState(null);
1326
1328
  setUser(null);
1329
+ profileLoadedRef.current = false;
1327
1330
  setSessionValid(false);
1328
1331
  setLoading(false);
1329
1332
  };
@@ -1339,7 +1342,7 @@ function AuthProvider({ children, onSessionExpired, manageSessionSecurity = true
1339
1342
  if (recoveredToken) {
1340
1343
  setTokenState(recoveredToken);
1341
1344
  setSessionValid(true);
1342
- setLoading(true);
1345
+ if (!profileLoadedRef.current) setLoading(true);
1343
1346
  return true;
1344
1347
  }
1345
1348
  } catch (error) {
@@ -1416,6 +1419,7 @@ function AuthProvider({ children, onSessionExpired, manageSessionSecurity = true
1416
1419
  const userData = (responseBody == null ? void 0 : responseBody.data) ?? responseBody;
1417
1420
  console.log("\u2705 Profile fetched successfully:", userData.email);
1418
1421
  setUser(userData);
1422
+ profileLoadedRef.current = true;
1419
1423
  setSessionValid(true);
1420
1424
  setLoading(false);
1421
1425
  } catch (error) {
@@ -1450,6 +1454,7 @@ function AuthProvider({ children, onSessionExpired, manageSessionSecurity = true
1450
1454
  if (cancelled) return;
1451
1455
  const userData = (responseBody == null ? void 0 : responseBody.data) ?? responseBody;
1452
1456
  setUser(userData);
1457
+ profileLoadedRef.current = true;
1453
1458
  setSessionValid(true);
1454
1459
  setLoading(false);
1455
1460
  return;
@@ -1496,7 +1501,7 @@ function AuthProvider({ children, onSessionExpired, manageSessionSecurity = true
1496
1501
  setToken(newToken);
1497
1502
  setTokenState(newToken);
1498
1503
  setSessionValid(true);
1499
- if (newToken) setLoading(true);
1504
+ if (newToken && !profileLoadedRef.current) setLoading(true);
1500
1505
  },
1501
1506
  clearToken: () => {
1502
1507
  stopSessionSecurity();
@@ -1504,6 +1509,7 @@ function AuthProvider({ children, onSessionExpired, manageSessionSecurity = true
1504
1509
  clearToken();
1505
1510
  setTokenState(null);
1506
1511
  setUser(null);
1512
+ profileLoadedRef.current = false;
1507
1513
  }
1508
1514
  };
1509
1515
  return /* @__PURE__ */ import_react.default.createElement(AuthContext.Provider, { value }, children);