@dynamic-labs/sdk-react-core 3.9.12 → 3.9.13
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/CHANGELOG.md +7 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +11 -11
- package/src/lib/context/DynamicContext/DynamicContext.cjs +2 -4
- package/src/lib/context/DynamicContext/DynamicContext.js +2 -4
- package/src/lib/utils/hooks/index.d.ts +1 -1
- package/src/lib/utils/hooks/useRefreshUserState/index.d.ts +1 -0
- package/src/lib/utils/hooks/{useResetCookieLocalStorage/useResetCookieLocalStorage.cjs → useRefreshUserState/useRefreshUserState.cjs} +29 -11
- package/src/lib/utils/hooks/useRefreshUserState/useRefreshUserState.d.ts +7 -0
- package/src/lib/utils/hooks/{useResetCookieLocalStorage/useResetCookieLocalStorage.js → useRefreshUserState/useRefreshUserState.js} +27 -9
- package/src/lib/utils/hooks/useResetCookieLocalStorage/index.d.ts +0 -1
- package/src/lib/utils/hooks/useResetCookieLocalStorage/useResetCookieLocalStorage.d.ts +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
|
|
2
|
+
### [3.9.13](https://github.com/dynamic-labs/DynamicAuth/compare/v3.9.12...v3.9.13) (2025-02-25)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* refresh user from valid token when user is missing from storage ([#8142](https://github.com/dynamic-labs/DynamicAuth/issues/8142)) ([b468815](https://github.com/dynamic-labs/DynamicAuth/commit/b4688156d005d77d1db8da4c4b2ef714da8e7e81))
|
|
8
|
+
|
|
2
9
|
### [3.9.12](https://github.com/dynamic-labs/DynamicAuth/compare/v3.9.11...v3.9.12) (2025-02-21)
|
|
3
10
|
|
|
4
11
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/sdk-react-core",
|
|
3
|
-
"version": "3.9.
|
|
3
|
+
"version": "3.9.13",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
"react-i18next": "13.5.0",
|
|
18
18
|
"yup": "0.32.11",
|
|
19
19
|
"react-international-phone": "4.2.5",
|
|
20
|
-
"@dynamic-labs/assert-package-version": "3.9.
|
|
21
|
-
"@dynamic-labs/iconic": "3.9.
|
|
22
|
-
"@dynamic-labs/logger": "3.9.
|
|
23
|
-
"@dynamic-labs/multi-wallet": "3.9.
|
|
24
|
-
"@dynamic-labs/rpc-providers": "3.9.
|
|
25
|
-
"@dynamic-labs/store": "3.9.
|
|
26
|
-
"@dynamic-labs/types": "3.9.
|
|
27
|
-
"@dynamic-labs/utils": "3.9.
|
|
28
|
-
"@dynamic-labs/wallet-book": "3.9.
|
|
29
|
-
"@dynamic-labs/wallet-connector-core": "3.9.
|
|
20
|
+
"@dynamic-labs/assert-package-version": "3.9.13",
|
|
21
|
+
"@dynamic-labs/iconic": "3.9.13",
|
|
22
|
+
"@dynamic-labs/logger": "3.9.13",
|
|
23
|
+
"@dynamic-labs/multi-wallet": "3.9.13",
|
|
24
|
+
"@dynamic-labs/rpc-providers": "3.9.13",
|
|
25
|
+
"@dynamic-labs/store": "3.9.13",
|
|
26
|
+
"@dynamic-labs/types": "3.9.13",
|
|
27
|
+
"@dynamic-labs/utils": "3.9.13",
|
|
28
|
+
"@dynamic-labs/wallet-book": "3.9.13",
|
|
29
|
+
"@dynamic-labs/wallet-connector-core": "3.9.13",
|
|
30
30
|
"bs58": "5.0.0",
|
|
31
31
|
"eventemitter3": "5.0.1"
|
|
32
32
|
},
|
|
@@ -67,9 +67,9 @@ var useSetWalletConnectorFetchers = require('../../utils/hooks/useSetWalletConne
|
|
|
67
67
|
var useSendDynamicProps = require('../../utils/hooks/useSendDynamicProps/useSendDynamicProps.cjs');
|
|
68
68
|
require('../../store/state/tokenBalances.cjs');
|
|
69
69
|
var WalletGroupContext = require('../WalletGroupContext/WalletGroupContext.cjs');
|
|
70
|
-
var useResetCookieLocalStorage = require('../../utils/hooks/useResetCookieLocalStorage/useResetCookieLocalStorage.cjs');
|
|
71
70
|
require('../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
|
|
72
71
|
var useAggregateWalletEvents = require('../../utils/hooks/useAggregateWalletEvents/useAggregateWalletEvents.cjs');
|
|
72
|
+
var useRefreshUserState = require('../../utils/hooks/useRefreshUserState/useRefreshUserState.cjs');
|
|
73
73
|
require('../../components/ShadowDOM/ShadowDOM.cjs');
|
|
74
74
|
require('../../components/IconButton/IconButton.cjs');
|
|
75
75
|
require('../../components/InlineWidget/InlineWidget.cjs');
|
|
@@ -355,9 +355,7 @@ const InnerDynamicContextProvider = ({ children, theme, settings: settings$1, lo
|
|
|
355
355
|
environmentId,
|
|
356
356
|
handleLogOut,
|
|
357
357
|
});
|
|
358
|
-
const { isLoading: isLoadingUserFromCookie } =
|
|
359
|
-
environmentId,
|
|
360
|
-
projectSettings: projectSettings$1,
|
|
358
|
+
const { isLoading: isLoadingUserFromCookie } = useRefreshUserState.useRefreshUserState({
|
|
361
359
|
setPrimaryWalletId,
|
|
362
360
|
});
|
|
363
361
|
const sdkHasLoaded = useGlobalLoading.useGlobalLoading({
|
|
@@ -63,9 +63,9 @@ import { useSetWalletConnectorFetchers } from '../../utils/hooks/useSetWalletCon
|
|
|
63
63
|
import { useSendDynamicProps } from '../../utils/hooks/useSendDynamicProps/useSendDynamicProps.js';
|
|
64
64
|
import '../../store/state/tokenBalances.js';
|
|
65
65
|
import { WalletGroupContextProvider } from '../WalletGroupContext/WalletGroupContext.js';
|
|
66
|
-
import { useResetCookieLocalStorage } from '../../utils/hooks/useResetCookieLocalStorage/useResetCookieLocalStorage.js';
|
|
67
66
|
import '../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
|
|
68
67
|
import { useAggregateWalletEvents } from '../../utils/hooks/useAggregateWalletEvents/useAggregateWalletEvents.js';
|
|
68
|
+
import { useRefreshUserState } from '../../utils/hooks/useRefreshUserState/useRefreshUserState.js';
|
|
69
69
|
import '../../components/ShadowDOM/ShadowDOM.js';
|
|
70
70
|
import '../../components/IconButton/IconButton.js';
|
|
71
71
|
import '../../components/InlineWidget/InlineWidget.js';
|
|
@@ -351,9 +351,7 @@ const InnerDynamicContextProvider = ({ children, theme, settings, locale, enable
|
|
|
351
351
|
environmentId,
|
|
352
352
|
handleLogOut,
|
|
353
353
|
});
|
|
354
|
-
const { isLoading: isLoadingUserFromCookie } =
|
|
355
|
-
environmentId,
|
|
356
|
-
projectSettings,
|
|
354
|
+
const { isLoading: isLoadingUserFromCookie } = useRefreshUserState({
|
|
357
355
|
setPrimaryWalletId,
|
|
358
356
|
});
|
|
359
357
|
const sdkHasLoaded = useGlobalLoading({
|
|
@@ -60,7 +60,6 @@ export { useSyncOnboardingFlow } from './useSyncOnboardingFlow';
|
|
|
60
60
|
export { useExternalAuth } from './useExternalAuth';
|
|
61
61
|
export { useRefreshUser } from './useRefreshUser';
|
|
62
62
|
export { useWalletOptions } from './useWalletOptions';
|
|
63
|
-
export { useResetCookieLocalStorage } from './useResetCookieLocalStorage';
|
|
64
63
|
export { useSyncMfaFlow } from './useSyncMfaFlow';
|
|
65
64
|
export * from './useSmartWallets';
|
|
66
65
|
export { useEmbeddedWalletSessionKeys } from './useEmbeddedWalletSessionKeys';
|
|
@@ -69,3 +68,4 @@ export { useDebounce } from './useDebounce';
|
|
|
69
68
|
export * from './useEmbeddedWallet';
|
|
70
69
|
export { useUpgradeEmbeddedWallet } from './useUpgradeEmbeddedWallet';
|
|
71
70
|
export { useAggregateWalletEvents } from './useAggregateWalletEvents';
|
|
71
|
+
export { useRefreshUserState } from './useRefreshUserState';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useRefreshUserState } from './useRefreshUserState';
|
|
@@ -18,6 +18,7 @@ require('../../constants/values.cjs');
|
|
|
18
18
|
require('../../../store/state/loadingAndLifecycle.cjs');
|
|
19
19
|
require('../../../shared/consts/index.cjs');
|
|
20
20
|
require('@dynamic-labs/multi-wallet');
|
|
21
|
+
var getAuthToken = require('../../functions/getAuthToken/getAuthToken.cjs');
|
|
21
22
|
require('react-international-phone');
|
|
22
23
|
require('../../../config/ApiEndpoint.cjs');
|
|
23
24
|
var user = require('../../../store/state/user/user.cjs');
|
|
@@ -25,11 +26,14 @@ require('../../../locale/locale.cjs');
|
|
|
25
26
|
var user$1 = require('../../../data/api/user/user.cjs');
|
|
26
27
|
var isCookieEnabled = require('../../functions/isCookieEnabled/isCookieEnabled.cjs');
|
|
27
28
|
var useDynamicEvents = require('../events/useDynamicEvents/useDynamicEvents.cjs');
|
|
29
|
+
var projectSettings = require('../../../store/state/projectSettings/projectSettings.cjs');
|
|
30
|
+
var environmentId = require('../../../store/state/environmentId.cjs');
|
|
28
31
|
|
|
29
|
-
const
|
|
32
|
+
const useRefreshUserState = ({ setPrimaryWalletId, }) => {
|
|
30
33
|
const [isLoading, setIsLoading] = React.useState(true);
|
|
31
34
|
const didRefreshUserRef = React.useRef(false);
|
|
32
|
-
const
|
|
35
|
+
const environmentId$1 = environmentId.useEnvironmentId();
|
|
36
|
+
const projectSettings$1 = projectSettings.useProjectSettings();
|
|
33
37
|
/**
|
|
34
38
|
* As an extra layer of safety, we must explicitly prevent the refresh from being called
|
|
35
39
|
* after a logout
|
|
@@ -56,36 +60,50 @@ const useResetCookieLocalStorage = ({ environmentId, projectSettings, setPrimary
|
|
|
56
60
|
* so attempt to set it here.
|
|
57
61
|
*/
|
|
58
62
|
const maybeInitUserRefresh = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
-
|
|
63
|
+
const mustRefreshUser = (() => {
|
|
64
|
+
// if user is present, we dont need to refresh anything
|
|
65
|
+
if (user.getUser())
|
|
66
|
+
return false;
|
|
67
|
+
// if the user has logged out, we dont need to refresh anything
|
|
68
|
+
if (hasLoggedOut.current)
|
|
69
|
+
return false;
|
|
70
|
+
// should run if cookie is enabled and no user is present
|
|
71
|
+
if (projectSettings$1 && isCookieEnabled.isCookieEnabled())
|
|
72
|
+
return true;
|
|
73
|
+
// should run if auth token is present but no user is present and cookie is not enabled
|
|
74
|
+
return Boolean(getAuthToken.getAuthToken());
|
|
75
|
+
})();
|
|
76
|
+
if (mustRefreshUser) {
|
|
60
77
|
// Disable all next calls to this method
|
|
61
78
|
didRefreshUserRef.current = true;
|
|
62
79
|
try {
|
|
63
|
-
const user = yield user$1.refreshUserJwt({ environmentId });
|
|
80
|
+
const user = yield user$1.refreshUserJwt({ environmentId: environmentId$1 });
|
|
64
81
|
/**
|
|
65
82
|
* attempt to set primary wallet in this subdomain because LS does not
|
|
66
83
|
* carry over between different subdomains, even if the cookie does
|
|
67
84
|
*/
|
|
68
85
|
const lastVerifiedWallet = user === null || user === void 0 ? void 0 : user.verifiedCredentials.find((vc) => vc.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.Blockchain &&
|
|
69
86
|
vc.id === user.lastVerifiedCredentialId);
|
|
70
|
-
if (lastVerifiedWallet)
|
|
87
|
+
if (lastVerifiedWallet) {
|
|
71
88
|
setPrimaryWalletId(lastVerifiedWallet.id);
|
|
89
|
+
}
|
|
72
90
|
}
|
|
73
91
|
catch (e) {
|
|
74
|
-
logger.logger.debug('Ignore failed refreshUserJwt in
|
|
92
|
+
logger.logger.debug('Ignore failed refreshUserJwt in useRefreshUserState');
|
|
75
93
|
}
|
|
76
94
|
}
|
|
77
|
-
if (projectSettings) {
|
|
95
|
+
if (projectSettings$1) {
|
|
78
96
|
// only set to false if projectSettings are available,
|
|
79
97
|
// otherwise isCookieEnabled might be a false negative
|
|
80
98
|
setIsLoading(false);
|
|
81
99
|
}
|
|
82
100
|
});
|
|
83
|
-
// Ensure this effect only runs once
|
|
84
|
-
if (didRefreshUserRef.current)
|
|
101
|
+
// Ensure this effect only runs once projectSettings is available
|
|
102
|
+
if (didRefreshUserRef.current || !projectSettings$1)
|
|
85
103
|
return;
|
|
86
104
|
maybeInitUserRefresh();
|
|
87
|
-
}, [
|
|
105
|
+
}, [projectSettings$1, environmentId$1, setPrimaryWalletId]);
|
|
88
106
|
return { isLoading };
|
|
89
107
|
};
|
|
90
108
|
|
|
91
|
-
exports.
|
|
109
|
+
exports.useRefreshUserState = useRefreshUserState;
|
|
@@ -14,6 +14,7 @@ import '../../constants/values.js';
|
|
|
14
14
|
import '../../../store/state/loadingAndLifecycle.js';
|
|
15
15
|
import '../../../shared/consts/index.js';
|
|
16
16
|
import '@dynamic-labs/multi-wallet';
|
|
17
|
+
import { getAuthToken } from '../../functions/getAuthToken/getAuthToken.js';
|
|
17
18
|
import 'react-international-phone';
|
|
18
19
|
import '../../../config/ApiEndpoint.js';
|
|
19
20
|
import { getUser } from '../../../store/state/user/user.js';
|
|
@@ -21,11 +22,14 @@ import '../../../locale/locale.js';
|
|
|
21
22
|
import { refreshUserJwt } from '../../../data/api/user/user.js';
|
|
22
23
|
import { isCookieEnabled } from '../../functions/isCookieEnabled/isCookieEnabled.js';
|
|
23
24
|
import { useInternalDynamicEvents } from '../events/useDynamicEvents/useDynamicEvents.js';
|
|
25
|
+
import { useProjectSettings } from '../../../store/state/projectSettings/projectSettings.js';
|
|
26
|
+
import { useEnvironmentId } from '../../../store/state/environmentId.js';
|
|
24
27
|
|
|
25
|
-
const
|
|
28
|
+
const useRefreshUserState = ({ setPrimaryWalletId, }) => {
|
|
26
29
|
const [isLoading, setIsLoading] = useState(true);
|
|
27
30
|
const didRefreshUserRef = useRef(false);
|
|
28
|
-
const
|
|
31
|
+
const environmentId = useEnvironmentId();
|
|
32
|
+
const projectSettings = useProjectSettings();
|
|
29
33
|
/**
|
|
30
34
|
* As an extra layer of safety, we must explicitly prevent the refresh from being called
|
|
31
35
|
* after a logout
|
|
@@ -52,7 +56,20 @@ const useResetCookieLocalStorage = ({ environmentId, projectSettings, setPrimary
|
|
|
52
56
|
* so attempt to set it here.
|
|
53
57
|
*/
|
|
54
58
|
const maybeInitUserRefresh = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
-
|
|
59
|
+
const mustRefreshUser = (() => {
|
|
60
|
+
// if user is present, we dont need to refresh anything
|
|
61
|
+
if (getUser())
|
|
62
|
+
return false;
|
|
63
|
+
// if the user has logged out, we dont need to refresh anything
|
|
64
|
+
if (hasLoggedOut.current)
|
|
65
|
+
return false;
|
|
66
|
+
// should run if cookie is enabled and no user is present
|
|
67
|
+
if (projectSettings && isCookieEnabled())
|
|
68
|
+
return true;
|
|
69
|
+
// should run if auth token is present but no user is present and cookie is not enabled
|
|
70
|
+
return Boolean(getAuthToken());
|
|
71
|
+
})();
|
|
72
|
+
if (mustRefreshUser) {
|
|
56
73
|
// Disable all next calls to this method
|
|
57
74
|
didRefreshUserRef.current = true;
|
|
58
75
|
try {
|
|
@@ -63,11 +80,12 @@ const useResetCookieLocalStorage = ({ environmentId, projectSettings, setPrimary
|
|
|
63
80
|
*/
|
|
64
81
|
const lastVerifiedWallet = user === null || user === void 0 ? void 0 : user.verifiedCredentials.find((vc) => vc.format === JwtVerifiedCredentialFormatEnum.Blockchain &&
|
|
65
82
|
vc.id === user.lastVerifiedCredentialId);
|
|
66
|
-
if (lastVerifiedWallet)
|
|
83
|
+
if (lastVerifiedWallet) {
|
|
67
84
|
setPrimaryWalletId(lastVerifiedWallet.id);
|
|
85
|
+
}
|
|
68
86
|
}
|
|
69
87
|
catch (e) {
|
|
70
|
-
logger.debug('Ignore failed refreshUserJwt in
|
|
88
|
+
logger.debug('Ignore failed refreshUserJwt in useRefreshUserState');
|
|
71
89
|
}
|
|
72
90
|
}
|
|
73
91
|
if (projectSettings) {
|
|
@@ -76,12 +94,12 @@ const useResetCookieLocalStorage = ({ environmentId, projectSettings, setPrimary
|
|
|
76
94
|
setIsLoading(false);
|
|
77
95
|
}
|
|
78
96
|
});
|
|
79
|
-
// Ensure this effect only runs once
|
|
80
|
-
if (didRefreshUserRef.current)
|
|
97
|
+
// Ensure this effect only runs once projectSettings is available
|
|
98
|
+
if (didRefreshUserRef.current || !projectSettings)
|
|
81
99
|
return;
|
|
82
100
|
maybeInitUserRefresh();
|
|
83
|
-
}, [
|
|
101
|
+
}, [projectSettings, environmentId, setPrimaryWalletId]);
|
|
84
102
|
return { isLoading };
|
|
85
103
|
};
|
|
86
104
|
|
|
87
|
-
export {
|
|
105
|
+
export { useRefreshUserState };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useResetCookieLocalStorage } from './useResetCookieLocalStorage';
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ProjectSettings } from '@dynamic-labs/sdk-api-core';
|
|
2
|
-
type Props = {
|
|
3
|
-
environmentId: string;
|
|
4
|
-
projectSettings: ProjectSettings | undefined;
|
|
5
|
-
setPrimaryWalletId(walletId: string): void;
|
|
6
|
-
};
|
|
7
|
-
export declare const useResetCookieLocalStorage: ({ environmentId, projectSettings, setPrimaryWalletId, }: Props) => {
|
|
8
|
-
isLoading: boolean;
|
|
9
|
-
};
|
|
10
|
-
export {};
|