@djangocfg/api 2.1.548 → 2.1.549

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/auth.cjs CHANGED
@@ -4604,6 +4604,7 @@ function AccountsProvider({ children }) {
4604
4604
  const [profileError, setProfileError] = (0, import_react15.useState)(null);
4605
4605
  const profileRef = (0, import_react15.useRef)(profile);
4606
4606
  const isLoadingRef = (0, import_react15.useRef)(false);
4607
+ const fetchSeqRef = (0, import_react15.useRef)(0);
4607
4608
  (0, import_react15.useEffect)(() => {
4608
4609
  profileRef.current = profile;
4609
4610
  }, [profile]);
@@ -4622,10 +4623,11 @@ function AccountsProvider({ children }) {
4622
4623
  authLogger.debug(`No API origin configured, skipping profile fetch (caller: ${callerId})`);
4623
4624
  return void 0;
4624
4625
  }
4625
- if (isLoadingRef.current) {
4626
+ if (isLoadingRef.current && !force) {
4626
4627
  authLogger.debug(`Profile loading in progress, skipping (caller: ${callerId})`);
4627
4628
  return profileRef.current;
4628
4629
  }
4630
+ const seq = ++fetchSeqRef.current;
4629
4631
  setIsLoadingProfile(true);
4630
4632
  isLoadingRef.current = true;
4631
4633
  setProfileError(null);
@@ -4633,17 +4635,20 @@ function AccountsProvider({ children }) {
4633
4635
  authLogger.debug(`Fetching profile from API (caller: ${callerId}, force: ${force})`);
4634
4636
  const res = await CfgAccountsProfile.cfgAccountsProfileRetrieve({ throwOnError: true });
4635
4637
  const result = res.data;
4638
+ if (seq !== fetchSeqRef.current) return result;
4636
4639
  setProfile(result);
4637
4640
  profileRef.current = result;
4638
4641
  setCachedProfile(result);
4639
4642
  return result;
4640
4643
  } catch (error) {
4641
4644
  const err = error instanceof Error ? error : new Error("Failed to fetch profile");
4642
- setProfileError(err);
4645
+ if (seq === fetchSeqRef.current) setProfileError(err);
4643
4646
  throw err;
4644
4647
  } finally {
4645
- setIsLoadingProfile(false);
4646
- isLoadingRef.current = false;
4648
+ if (seq === fetchSeqRef.current) {
4649
+ setIsLoadingProfile(false);
4650
+ isLoadingRef.current = false;
4651
+ }
4647
4652
  }
4648
4653
  }, []);
4649
4654
  const updateProfile = (0, import_react15.useCallback)(async (data) => {