@djangocfg/api 2.1.190 → 2.1.192

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
@@ -75,6 +75,7 @@ module.exports = __toCommonJS(auth_exports);
75
75
  // src/auth/context/AuthContext.tsx
76
76
  var import_navigation4 = require("next/navigation");
77
77
  var import_react17 = require("react");
78
+ var import_swr18 = require("swr");
78
79
 
79
80
  // src/auth/hooks/useCfgRouter.ts
80
81
  var import_navigation = require("next/navigation");
@@ -5835,6 +5836,18 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
5835
5836
  }
5836
5837
  return false;
5837
5838
  }, [clearAuthState]);
5839
+ const isAutoLoggingOutRef = (0, import_react17.useRef)(false);
5840
+ const swrOnError = (0, import_react17.useCallback)((error) => {
5841
+ const isAuthError = error?.status === 401 || error?.statusCode === 401 || error?.code === "token_not_valid" || error?.code === "authentication_failed";
5842
+ if (isAuthError && !isAutoLoggingOutRef.current) {
5843
+ isAutoLoggingOutRef.current = true;
5844
+ authLogger.warn("SWR 401 error detected, auto-logout");
5845
+ clearAuthState("swrOnError:401");
5846
+ const authCallbackUrl = configRef.current?.routes?.defaultAuthCallback || defaultRoutes.defaultAuthCallback;
5847
+ router.hardReplace(authCallbackUrl);
5848
+ }
5849
+ }, [clearAuthState, router]);
5850
+ const swrConfig = (0, import_react17.useMemo)(() => ({ onError: swrOnError }), [swrOnError]);
5838
5851
  const loadCurrentProfile = (0, import_react17.useCallback)(async (callerId) => {
5839
5852
  const finalCallerId = callerId || "AuthContext.loadCurrentProfile";
5840
5853
  if (isLoadingProfileRef.current) {
@@ -6179,7 +6192,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
6179
6192
  uploadAvatar
6180
6193
  ]
6181
6194
  );
6182
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AuthContext.Provider, { value, children });
6195
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AuthContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_swr18.SWRConfig, { value: swrConfig, children }) });
6183
6196
  }, "AuthProviderInternal");
6184
6197
  var AuthProvider = /* @__PURE__ */ __name(({ children, config }) => {
6185
6198
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AccountsProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AuthProviderInternal, { config, children }) });