@djangocfg/api 2.1.604 → 2.1.606

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
@@ -4632,6 +4632,30 @@ var useDeleteAccount = /* @__PURE__ */ __name(() => {
4632
4632
  };
4633
4633
  }, "useDeleteAccount");
4634
4634
 
4635
+ // src/auth/hooks/legacyStorage.ts
4636
+ var LEGACY_TOKEN_KEYS = [
4637
+ "cfg.auth.access_token",
4638
+ "cfg.auth.refresh_token",
4639
+ "auth_token",
4640
+ "refresh_token",
4641
+ "access_token"
4642
+ ];
4643
+ function purgeLegacyTokenStorage() {
4644
+ const removed = [];
4645
+ try {
4646
+ if (typeof window === "undefined") return removed;
4647
+ for (const key of LEGACY_TOKEN_KEYS) {
4648
+ if (window.localStorage.getItem(key) !== null) {
4649
+ window.localStorage.removeItem(key);
4650
+ removed.push(key);
4651
+ }
4652
+ }
4653
+ } catch {
4654
+ }
4655
+ return removed;
4656
+ }
4657
+ __name(purgeLegacyTokenStorage, "purgeLegacyTokenStorage");
4658
+
4635
4659
  // src/auth/context/AccountsContext.tsx
4636
4660
  var import_react19 = require("react");
4637
4661
 
@@ -4996,6 +5020,10 @@ __name(hasApiOrigin, "hasApiOrigin");
4996
5020
  var AccountsContext = (0, import_react19.createContext)(void 0);
4997
5021
  function AccountsProvider({ children }) {
4998
5022
  const [profile, setProfile] = (0, import_react19.useState)(() => {
5023
+ if (!auth.isAuthenticated()) {
5024
+ clearProfileCache();
5025
+ return void 0;
5026
+ }
4999
5027
  const cached = getCachedProfile();
5000
5028
  return cached || void 0;
5001
5029
  });
@@ -5196,6 +5224,10 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
5196
5224
  authLogger.warn("Dead session in storage \u2014 clearing");
5197
5225
  auth.clearSession();
5198
5226
  clearProfileCache();
5227
+ } else if (!hasTokens && !auth.isAuthenticated()) {
5228
+ clearProfileCache();
5229
+ purgeLegacyTokenStorage();
5230
+ if (accountsRef.current.profile) accountsRef.current.logout();
5199
5231
  }
5200
5232
  setProfileSettled(true);
5201
5233
  return;