@djangocfg/api 2.1.606 → 2.1.608
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 -3
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +5 -3
- package/dist/auth.d.ts +5 -3
- package/dist/auth.mjs +44 -33
- package/dist/auth.mjs.map +1 -1
- package/package.json +2 -2
- package/src/auth/__tests__/useOAuthLogin.test.tsx +17 -2
- package/src/auth/context/AuthContext.tsx +2 -2
- package/src/auth/hooks/useOAuthProviders.ts +27 -8
package/dist/auth.d.cts
CHANGED
|
@@ -977,9 +977,11 @@ interface UseOAuthProvidersReturn {
|
|
|
977
977
|
*
|
|
978
978
|
* Fetched once per page session and kept in `sessionStorage`, so a reload or
|
|
979
979
|
* "Try again" after a failed callback shows the buttons at once; the server
|
|
980
|
-
* answer always wins. A
|
|
981
|
-
*
|
|
982
|
-
*
|
|
980
|
+
* answer always wins. A failed request is retried twice (a dropped mobile
|
|
981
|
+
* connection or a gateway 502 must not hide the buttons for the whole visit);
|
|
982
|
+
* only when the retries fail too does the hook yield the cached list, else
|
|
983
|
+
* `[]`, with `isReady: true`: the email form never waits on, or breaks
|
|
984
|
+
* because of, this list. Ids this client has no adapter for (a newer backend) are dropped.
|
|
983
985
|
*/
|
|
984
986
|
declare const useOAuthProviders: () => UseOAuthProvidersReturn;
|
|
985
987
|
|
package/dist/auth.d.ts
CHANGED
|
@@ -977,9 +977,11 @@ interface UseOAuthProvidersReturn {
|
|
|
977
977
|
*
|
|
978
978
|
* Fetched once per page session and kept in `sessionStorage`, so a reload or
|
|
979
979
|
* "Try again" after a failed callback shows the buttons at once; the server
|
|
980
|
-
* answer always wins. A
|
|
981
|
-
*
|
|
982
|
-
*
|
|
980
|
+
* answer always wins. A failed request is retried twice (a dropped mobile
|
|
981
|
+
* connection or a gateway 502 must not hide the buttons for the whole visit);
|
|
982
|
+
* only when the retries fail too does the hook yield the cached list, else
|
|
983
|
+
* `[]`, with `isReady: true`: the email form never waits on, or breaks
|
|
984
|
+
* because of, this list. Ids this client has no adapter for (a newer backend) are dropped.
|
|
983
985
|
*/
|
|
984
986
|
declare const useOAuthProviders: () => UseOAuthProvidersReturn;
|
|
985
987
|
|
package/dist/auth.mjs
CHANGED
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
useEffect as useEffect7,
|
|
26
26
|
useMemo as useMemo4,
|
|
27
27
|
useRef as useRef7,
|
|
28
|
-
useState as
|
|
28
|
+
useState as useState12
|
|
29
29
|
} from "react";
|
|
30
30
|
|
|
31
31
|
// src/_api/generated/helpers/errors.ts
|
|
@@ -3616,7 +3616,7 @@ var useOAuthLogin = /* @__PURE__ */ __name((options = {}) => {
|
|
|
3616
3616
|
}, "useOAuthLogin");
|
|
3617
3617
|
|
|
3618
3618
|
// src/auth/hooks/useOAuthProviders.ts
|
|
3619
|
-
import { useMemo as useMemo2, useSyncExternalStore as useSyncExternalStore4 } from "react";
|
|
3619
|
+
import { useMemo as useMemo2, useState as useState5, useSyncExternalStore as useSyncExternalStore4 } from "react";
|
|
3620
3620
|
|
|
3621
3621
|
// src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthProvidersRetrieve.ts
|
|
3622
3622
|
import useSWR from "swr";
|
|
@@ -3672,6 +3672,8 @@ __name(useCfgAccountsOauthProvidersRetrieve, "useCfgAccountsOauthProvidersRetrie
|
|
|
3672
3672
|
// src/auth/hooks/useOAuthProviders.ts
|
|
3673
3673
|
var EMPTY = [];
|
|
3674
3674
|
var CACHE_KEY = CFG_KEYS.oauthProviders.key;
|
|
3675
|
+
var OAUTH_PROVIDERS_MAX_RETRIES = 2;
|
|
3676
|
+
var OAUTH_PROVIDERS_RETRY_MS = 1e3;
|
|
3675
3677
|
var isInfo = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null && typeof value.id === "string", "isInfo");
|
|
3676
3678
|
var lastRaw = null;
|
|
3677
3679
|
var lastParsed;
|
|
@@ -3692,14 +3694,23 @@ var subscribe3 = /* @__PURE__ */ __name(() => () => {
|
|
|
3692
3694
|
var serverSnapshot = /* @__PURE__ */ __name(() => void 0, "serverSnapshot");
|
|
3693
3695
|
var useOAuthProviders = /* @__PURE__ */ __name(() => {
|
|
3694
3696
|
const cached = useSyncExternalStore4(subscribe3, readCached, serverSnapshot);
|
|
3695
|
-
const
|
|
3697
|
+
const [failed, setFailed] = useState5(false);
|
|
3698
|
+
const { data } = useCfgAccountsOauthProvidersRetrieve(void 0, {
|
|
3696
3699
|
revalidateOnFocus: false,
|
|
3697
3700
|
revalidateOnReconnect: false,
|
|
3698
3701
|
revalidateOnMount: true,
|
|
3699
|
-
shouldRetryOnError:
|
|
3702
|
+
shouldRetryOnError: true,
|
|
3703
|
+
onErrorRetry: /* @__PURE__ */ __name((_error, _key, _config, revalidate, opts) => {
|
|
3704
|
+
if (opts.retryCount > OAUTH_PROVIDERS_MAX_RETRIES) {
|
|
3705
|
+
setFailed(true);
|
|
3706
|
+
return;
|
|
3707
|
+
}
|
|
3708
|
+
setTimeout(() => void revalidate(opts), OAUTH_PROVIDERS_RETRY_MS * opts.retryCount);
|
|
3709
|
+
}, "onErrorRetry"),
|
|
3700
3710
|
dedupingInterval: 60 * 60 * 1e3,
|
|
3701
3711
|
fallbackData: cached && { providers: cached },
|
|
3702
3712
|
onSuccess: /* @__PURE__ */ __name((response) => {
|
|
3713
|
+
setFailed(false);
|
|
3703
3714
|
cfgStorage.writeJSON(CACHE_KEY, response.providers);
|
|
3704
3715
|
}, "onSuccess")
|
|
3705
3716
|
});
|
|
@@ -3707,7 +3718,7 @@ var useOAuthProviders = /* @__PURE__ */ __name(() => {
|
|
|
3707
3718
|
() => data?.providers.filter((p) => OAUTH_PROVIDER_IDS.includes(p.id)) ?? EMPTY,
|
|
3708
3719
|
[data]
|
|
3709
3720
|
);
|
|
3710
|
-
return { providers, isReady:
|
|
3721
|
+
return { providers, isReady: data !== void 0 || failed || cached !== void 0 };
|
|
3711
3722
|
}, "useOAuthProviders");
|
|
3712
3723
|
|
|
3713
3724
|
// src/auth/hooks/useGithubAuth.ts
|
|
@@ -3723,7 +3734,7 @@ var useGithubAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
|
3723
3734
|
}, "useGithubAuth");
|
|
3724
3735
|
|
|
3725
3736
|
// src/auth/hooks/useTwoFactorVerify.ts
|
|
3726
|
-
import { useCallback as useCallback8, useState as
|
|
3737
|
+
import { useCallback as useCallback8, useState as useState6 } from "react";
|
|
3727
3738
|
|
|
3728
3739
|
// src/auth/hooks/twoFactor.shared.ts
|
|
3729
3740
|
var TOTP_CODE_LENGTH = 6;
|
|
@@ -3744,11 +3755,11 @@ __name(isValidTotpCode, "isValidTotpCode");
|
|
|
3744
3755
|
var useTwoFactorVerify = /* @__PURE__ */ __name((options = {}) => {
|
|
3745
3756
|
const { onSuccess, onError, redirectUrl, skipRedirect = false } = options;
|
|
3746
3757
|
const router = useCfgRouter();
|
|
3747
|
-
const [isLoading, setIsLoading] =
|
|
3748
|
-
const [error, setError] =
|
|
3749
|
-
const [warning, setWarning] =
|
|
3750
|
-
const [remainingBackupCodes, setRemainingBackupCodes] =
|
|
3751
|
-
const [attemptsRemaining, setAttemptsRemaining] =
|
|
3758
|
+
const [isLoading, setIsLoading] = useState6(false);
|
|
3759
|
+
const [error, setError] = useState6(null);
|
|
3760
|
+
const [warning, setWarning] = useState6(null);
|
|
3761
|
+
const [remainingBackupCodes, setRemainingBackupCodes] = useState6(null);
|
|
3762
|
+
const [attemptsRemaining, setAttemptsRemaining] = useState6(null);
|
|
3752
3763
|
const clearError = useCallback8(() => {
|
|
3753
3764
|
setError(null);
|
|
3754
3765
|
}, []);
|
|
@@ -3876,15 +3887,15 @@ var useTwoFactorVerify = /* @__PURE__ */ __name((options = {}) => {
|
|
|
3876
3887
|
}, "useTwoFactorVerify");
|
|
3877
3888
|
|
|
3878
3889
|
// src/auth/hooks/useTwoFactorSetup.ts
|
|
3879
|
-
import { useCallback as useCallback9, useState as
|
|
3890
|
+
import { useCallback as useCallback9, useState as useState7 } from "react";
|
|
3880
3891
|
var useTwoFactorSetup = /* @__PURE__ */ __name((options = {}) => {
|
|
3881
3892
|
const { onComplete, onError } = options;
|
|
3882
|
-
const [isLoading, setIsLoading] =
|
|
3883
|
-
const [error, setError] =
|
|
3884
|
-
const [setupData, setSetupData] =
|
|
3885
|
-
const [backupCodes, setBackupCodes] =
|
|
3886
|
-
const [backupCodesWarning, setBackupCodesWarning] =
|
|
3887
|
-
const [setupStep, setSetupStep] =
|
|
3893
|
+
const [isLoading, setIsLoading] = useState7(false);
|
|
3894
|
+
const [error, setError] = useState7(null);
|
|
3895
|
+
const [setupData, setSetupData] = useState7(null);
|
|
3896
|
+
const [backupCodes, setBackupCodes] = useState7(null);
|
|
3897
|
+
const [backupCodesWarning, setBackupCodesWarning] = useState7(null);
|
|
3898
|
+
const [setupStep, setSetupStep] = useState7("idle");
|
|
3888
3899
|
const clearError = useCallback9(() => {
|
|
3889
3900
|
setError(null);
|
|
3890
3901
|
}, []);
|
|
@@ -3983,12 +3994,12 @@ var useTwoFactorSetup = /* @__PURE__ */ __name((options = {}) => {
|
|
|
3983
3994
|
}, "useTwoFactorSetup");
|
|
3984
3995
|
|
|
3985
3996
|
// src/auth/hooks/useTwoFactorStatus.ts
|
|
3986
|
-
import { useCallback as useCallback10, useState as
|
|
3997
|
+
import { useCallback as useCallback10, useState as useState8 } from "react";
|
|
3987
3998
|
var useTwoFactorStatus = /* @__PURE__ */ __name(() => {
|
|
3988
|
-
const [isLoading, setIsLoading] =
|
|
3989
|
-
const [error, setError] =
|
|
3990
|
-
const [has2FAEnabled, setHas2FAEnabled] =
|
|
3991
|
-
const [devices, setDevices] =
|
|
3999
|
+
const [isLoading, setIsLoading] = useState8(false);
|
|
4000
|
+
const [error, setError] = useState8(null);
|
|
4001
|
+
const [has2FAEnabled, setHas2FAEnabled] = useState8(null);
|
|
4002
|
+
const [devices, setDevices] = useState8([]);
|
|
3992
4003
|
const clearError = useCallback10(() => {
|
|
3993
4004
|
setError(null);
|
|
3994
4005
|
}, []);
|
|
@@ -4060,9 +4071,9 @@ var useTwoFactor = /* @__PURE__ */ __name((options = {}) => {
|
|
|
4060
4071
|
}, "useTwoFactor");
|
|
4061
4072
|
|
|
4062
4073
|
// src/auth/hooks/useLocalStorage.ts
|
|
4063
|
-
import { useState as
|
|
4074
|
+
import { useState as useState9 } from "react";
|
|
4064
4075
|
function useLocalStorage(key, initialValue) {
|
|
4065
|
-
const [storedValue, setStoredValue] =
|
|
4076
|
+
const [storedValue, setStoredValue] = useState9(() => {
|
|
4066
4077
|
if (typeof window === "undefined") {
|
|
4067
4078
|
return initialValue;
|
|
4068
4079
|
}
|
|
@@ -4343,10 +4354,10 @@ function getCacheMetadata() {
|
|
|
4343
4354
|
__name(getCacheMetadata, "getCacheMetadata");
|
|
4344
4355
|
|
|
4345
4356
|
// src/auth/hooks/useDeleteAccount.ts
|
|
4346
|
-
import { useCallback as useCallback11, useState as
|
|
4357
|
+
import { useCallback as useCallback11, useState as useState10 } from "react";
|
|
4347
4358
|
var useDeleteAccount = /* @__PURE__ */ __name(() => {
|
|
4348
|
-
const [isLoading, setIsLoading] =
|
|
4349
|
-
const [error, setError] =
|
|
4359
|
+
const [isLoading, setIsLoading] = useState10(false);
|
|
4360
|
+
const [error, setError] = useState10(null);
|
|
4350
4361
|
const { logout } = useAuth();
|
|
4351
4362
|
const clearError = useCallback11(() => {
|
|
4352
4363
|
setError(null);
|
|
@@ -4412,7 +4423,7 @@ import {
|
|
|
4412
4423
|
useEffect as useEffect6,
|
|
4413
4424
|
useMemo as useMemo3,
|
|
4414
4425
|
useRef as useRef6,
|
|
4415
|
-
useState as
|
|
4426
|
+
useState as useState11
|
|
4416
4427
|
} from "react";
|
|
4417
4428
|
|
|
4418
4429
|
// src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyRegenerateCreate.ts
|
|
@@ -4775,7 +4786,7 @@ function hasApiOrigin() {
|
|
|
4775
4786
|
__name(hasApiOrigin, "hasApiOrigin");
|
|
4776
4787
|
var AccountsContext = createContext(void 0);
|
|
4777
4788
|
function AccountsProvider({ children }) {
|
|
4778
|
-
const [profile, setProfile] =
|
|
4789
|
+
const [profile, setProfile] = useState11(() => {
|
|
4779
4790
|
if (!auth.isAuthenticated()) {
|
|
4780
4791
|
clearProfileCache();
|
|
4781
4792
|
return void 0;
|
|
@@ -4783,8 +4794,8 @@ function AccountsProvider({ children }) {
|
|
|
4783
4794
|
const cached = getCachedProfile();
|
|
4784
4795
|
return cached || void 0;
|
|
4785
4796
|
});
|
|
4786
|
-
const [isLoadingProfile, setIsLoadingProfile] =
|
|
4787
|
-
const [profileError, setProfileError] =
|
|
4797
|
+
const [isLoadingProfile, setIsLoadingProfile] = useState11(false);
|
|
4798
|
+
const [profileError, setProfileError] = useState11(null);
|
|
4788
4799
|
const profileRef = useRef6(profile);
|
|
4789
4800
|
const isLoadingRef = useRef6(false);
|
|
4790
4801
|
const fetchSeqRef = useRef6(0);
|
|
@@ -4969,7 +4980,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4969
4980
|
accountsRef.current = accounts;
|
|
4970
4981
|
}, [accounts]);
|
|
4971
4982
|
const pendingManualNavRef = useRef7(false);
|
|
4972
|
-
const [profileSettled, setProfileSettled] =
|
|
4983
|
+
const [profileSettled, setProfileSettled] = useState12(false);
|
|
4973
4984
|
const hasProfile = Boolean(accounts.profile);
|
|
4974
4985
|
const profileAttemptedRef = useRef7(false);
|
|
4975
4986
|
useEffect7(() => {
|