@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 +14 -1
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.mjs +14 -1
- package/dist/auth.mjs.map +1 -1
- package/package.json +2 -2
- package/src/auth/context/AuthContext.tsx +25 -1
package/dist/auth.mjs
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
useRef as useRef5,
|
|
18
18
|
useState as useState12
|
|
19
19
|
} from "react";
|
|
20
|
+
import { SWRConfig } from "swr";
|
|
20
21
|
|
|
21
22
|
// src/auth/hooks/useCfgRouter.ts
|
|
22
23
|
import { useRouter as useNextRouter } from "next/navigation";
|
|
@@ -5784,6 +5785,18 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
5784
5785
|
}
|
|
5785
5786
|
return false;
|
|
5786
5787
|
}, [clearAuthState]);
|
|
5788
|
+
const isAutoLoggingOutRef = useRef5(false);
|
|
5789
|
+
const swrOnError = useCallback12((error) => {
|
|
5790
|
+
const isAuthError = error?.status === 401 || error?.statusCode === 401 || error?.code === "token_not_valid" || error?.code === "authentication_failed";
|
|
5791
|
+
if (isAuthError && !isAutoLoggingOutRef.current) {
|
|
5792
|
+
isAutoLoggingOutRef.current = true;
|
|
5793
|
+
authLogger.warn("SWR 401 error detected, auto-logout");
|
|
5794
|
+
clearAuthState("swrOnError:401");
|
|
5795
|
+
const authCallbackUrl = configRef.current?.routes?.defaultAuthCallback || defaultRoutes.defaultAuthCallback;
|
|
5796
|
+
router.hardReplace(authCallbackUrl);
|
|
5797
|
+
}
|
|
5798
|
+
}, [clearAuthState, router]);
|
|
5799
|
+
const swrConfig = useMemo2(() => ({ onError: swrOnError }), [swrOnError]);
|
|
5787
5800
|
const loadCurrentProfile = useCallback12(async (callerId) => {
|
|
5788
5801
|
const finalCallerId = callerId || "AuthContext.loadCurrentProfile";
|
|
5789
5802
|
if (isLoadingProfileRef.current) {
|
|
@@ -6128,7 +6141,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
6128
6141
|
uploadAvatar
|
|
6129
6142
|
]
|
|
6130
6143
|
);
|
|
6131
|
-
return /* @__PURE__ */ jsx2(AuthContext.Provider, { value, children });
|
|
6144
|
+
return /* @__PURE__ */ jsx2(AuthContext.Provider, { value, children: /* @__PURE__ */ jsx2(SWRConfig, { value: swrConfig, children }) });
|
|
6132
6145
|
}, "AuthProviderInternal");
|
|
6133
6146
|
var AuthProvider = /* @__PURE__ */ __name(({ children, config }) => {
|
|
6134
6147
|
return /* @__PURE__ */ jsx2(AccountsProvider, { children: /* @__PURE__ */ jsx2(AuthProviderInternal, { config, children }) });
|