@dynamic-labs/sdk-react-core 3.0.0-alpha.32 → 3.0.0-alpha.34
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 +9 -0
- package/package.cjs +2 -2
- package/package.js +2 -2
- package/package.json +12 -12
- package/src/lib/components/AuthProviderIcon/AuthProviderIcon.cjs +2 -2
- package/src/lib/components/AuthProviderIcon/AuthProviderIcon.js +2 -2
- package/src/lib/components/SyncAuthFlow/SyncAuthFlow.cjs +2 -0
- package/src/lib/components/SyncAuthFlow/SyncAuthFlow.js +2 -0
- package/src/lib/context/DynamicContext/DynamicContext.cjs +17 -11
- package/src/lib/context/DynamicContext/DynamicContext.js +17 -11
- package/src/lib/context/DynamicContext/types/IDynamicContext.d.ts +1 -2
- package/src/lib/context/DynamicContext/useDynamicContext/useDynamicContext.cjs +2 -2
- package/src/lib/context/DynamicContext/useDynamicContext/useDynamicContext.d.ts +1 -1
- package/src/lib/context/DynamicContext/useDynamicContext/useDynamicContext.js +2 -2
- package/src/lib/context/PhantomRedirectContext/useResponseHandlers.cjs +3 -3
- package/src/lib/context/PhantomRedirectContext/useResponseHandlers.js +3 -3
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.cjs +5 -6
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.js +5 -6
- package/src/lib/data/api/embeddedWallets/embeddedWallets.cjs +1 -1
- package/src/lib/data/api/embeddedWallets/embeddedWallets.js +2 -2
- package/src/lib/data/api/embeddedWallets/types.d.ts +2 -2
- package/src/lib/data/api/externalAuth/externalAuth.cjs +20 -0
- package/src/lib/data/api/externalAuth/externalAuth.d.ts +4 -0
- package/src/lib/data/api/externalAuth/externalAuth.js +20 -1
- package/src/lib/events/auth.d.ts +12 -0
- package/src/lib/shared/utils/functions/hasPendingMfaAction/hasPendingMfaAction.cjs +14 -0
- package/src/lib/shared/utils/functions/hasPendingMfaAction/hasPendingMfaAction.d.ts +2 -0
- package/src/lib/shared/utils/functions/hasPendingMfaAction/hasPendingMfaAction.js +10 -0
- package/src/lib/shared/utils/functions/hasPendingMfaAction/index.d.ts +1 -0
- package/src/lib/shared/utils/functions/index.d.ts +1 -0
- package/src/lib/store/hooks/useUser/useUser.cjs +24 -6
- package/src/lib/store/hooks/useUser/useUser.d.ts +6 -3
- package/src/lib/store/hooks/useUser/useUser.js +24 -6
- package/src/lib/utils/functions/walletListBuilder/walletListBuilder.cjs +1 -1
- package/src/lib/utils/functions/walletListBuilder/walletListBuilder.js +1 -1
- package/src/lib/utils/hooks/authenticationHooks/useOtpVerificationRequest/useOtpVerificationRequest.cjs +3 -3
- package/src/lib/utils/hooks/authenticationHooks/useOtpVerificationRequest/useOtpVerificationRequest.js +3 -3
- package/src/lib/utils/hooks/events/useDynamicEvents/useDynamicEvents.cjs +2 -0
- package/src/lib/utils/hooks/events/useDynamicEvents/useDynamicEvents.d.ts +1 -1
- package/src/lib/utils/hooks/events/useDynamicEvents/useDynamicEvents.js +2 -0
- package/src/lib/utils/hooks/index.d.ts +2 -0
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.cjs +2 -1
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.js +2 -1
- package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.cjs +3 -1
- package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.d.ts +2 -2
- package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.js +4 -2
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.cjs +2 -2
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.d.ts +2 -2
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +2 -2
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useCoinbaseMPC/useCoinbaseMPC.cjs +1 -1
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useCoinbaseMPC/useCoinbaseMPC.d.ts +2 -2
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useCoinbaseMPC/useCoinbaseMPC.js +2 -2
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useMPCEmbeddedWallet.d.ts +3 -3
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.d.ts +2 -2
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useTurnkey/useTurnkey.d.ts +2 -2
- package/src/lib/utils/hooks/useExternalAuth/useExternalAuth.cjs +30 -1
- package/src/lib/utils/hooks/useExternalAuth/useExternalAuth.d.ts +1 -0
- package/src/lib/utils/hooks/useExternalAuth/useExternalAuth.js +31 -2
- package/src/lib/utils/hooks/useMfa/useMfa.cjs +8 -28
- package/src/lib/utils/hooks/useMfa/useMfa.d.ts +1 -7
- package/src/lib/utils/hooks/useMfa/useMfa.js +8 -28
- package/src/lib/utils/hooks/useResetCookieLocalStorage/index.d.ts +1 -0
- package/src/lib/utils/hooks/useResetCookieLocalStorage/useResetCookieLocalStorage.cjs +143 -0
- package/src/lib/utils/hooks/useResetCookieLocalStorage/useResetCookieLocalStorage.d.ts +8 -0
- package/src/lib/utils/hooks/useResetCookieLocalStorage/useResetCookieLocalStorage.js +139 -0
- package/src/lib/utils/hooks/useSyncMfaFlow/index.d.ts +1 -0
- package/src/lib/utils/hooks/useSyncMfaFlow/useSyncMfaFlow.cjs +152 -0
- package/src/lib/utils/hooks/useSyncMfaFlow/useSyncMfaFlow.d.ts +4 -0
- package/src/lib/utils/hooks/useSyncMfaFlow/useSyncMfaFlow.js +148 -0
- package/src/lib/utils/hooks/useSyncOnboardingFlow/useSyncOnboardingFlow.cjs +9 -7
- package/src/lib/utils/hooks/useSyncOnboardingFlow/useSyncOnboardingFlow.js +9 -7
- package/src/lib/utils/hooks/useUserAuth/useUserAuth.cjs +8 -14
- package/src/lib/utils/hooks/useUserAuth/useUserAuth.js +8 -14
- package/src/lib/utils/hooks/useUserUpdateRequest/useUpdateUser/useUpdateUser.cjs +3 -3
- package/src/lib/utils/hooks/useUserUpdateRequest/useUpdateUser/useUpdateUser.js +3 -3
- package/src/lib/views/CollectUserDataView/CollectUserDataView.cjs +4 -4
- package/src/lib/views/CollectUserDataView/CollectUserDataView.js +4 -4
- package/src/lib/views/CollectUserDataView/OnboardingUserDataForm/OnboardingUserDataForm.cjs +3 -3
- package/src/lib/views/CollectUserDataView/OnboardingUserDataForm/OnboardingUserDataForm.js +3 -3
- package/src/lib/views/CollectUserDataViewNoWallet/CollectUserDataViewNoWallet.cjs +3 -3
- package/src/lib/views/CollectUserDataViewNoWallet/CollectUserDataViewNoWallet.js +3 -3
- package/src/lib/views/EmailVerification/EmailVerification.cjs +4 -4
- package/src/lib/views/EmailVerification/EmailVerification.js +4 -4
- package/src/lib/views/MfaVerificationView/MfaVerificationView.cjs +2 -2
- package/src/lib/views/MfaVerificationView/MfaVerificationView.js +2 -2
- package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.cjs +2 -2
- package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.d.ts +2 -2
- package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.js +2 -2
- package/src/lib/views/Passkey/utils/createEmbeddedWalletRequest/createEmbeddedWalletRequest.d.ts +2 -2
- package/src/lib/views/SmsVerification/useSmsVerification/useSmsVerification.cjs +3 -3
- package/src/lib/views/SmsVerification/useSmsVerification/useSmsVerification.js +3 -3
- package/src/lib/views/viewToComponentMap.d.ts +1 -1
- package/src/lib/context/DynamicContext/hooks/useIsAuthenticated/index.d.ts +0 -1
- package/src/lib/context/DynamicContext/hooks/useIsAuthenticated/useIsAuthenticated.cjs +0 -8
- package/src/lib/context/DynamicContext/hooks/useIsAuthenticated/useIsAuthenticated.d.ts +0 -2
- package/src/lib/context/DynamicContext/hooks/useIsAuthenticated/useIsAuthenticated.js +0 -4
|
@@ -121,7 +121,36 @@ const useExternalAuth = () => {
|
|
|
121
121
|
throw e;
|
|
122
122
|
}
|
|
123
123
|
}), [environmentId, setCallback, setShowAuthFlow]);
|
|
124
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Uses a properly-configured non-Dynamic external JWT and user ID to verify the user in Dynamic.
|
|
126
|
+
* When successful, this should verify the user's access to Dynamic's functionality
|
|
127
|
+
* available to only signed-in users, such as wallet linking, etc.
|
|
128
|
+
*
|
|
129
|
+
* @param {string} props.externalJwt - JWT issued outside of Dynamic
|
|
130
|
+
* @param {string} props.externalUserId - User ID to identify the user outside of Dynamic
|
|
131
|
+
*
|
|
132
|
+
* @returns {UserProfile} - User profile for successfully verified user
|
|
133
|
+
*/
|
|
134
|
+
const verifyWithExternalJwt = React.useCallback((_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ externalUserId, externalJwt, }) {
|
|
135
|
+
try {
|
|
136
|
+
const userProfile = yield externalAuth.externalAuthVerify({
|
|
137
|
+
environmentId,
|
|
138
|
+
externalJwt,
|
|
139
|
+
});
|
|
140
|
+
setCallback('authSuccess');
|
|
141
|
+
setShowAuthFlow(false);
|
|
142
|
+
return userProfile;
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
dynamicEvents.dynamicEvents.emit('authFailure', {
|
|
146
|
+
externalUserId,
|
|
147
|
+
option: externalUserId,
|
|
148
|
+
type: 'externalAuth',
|
|
149
|
+
}, { error: e });
|
|
150
|
+
throw e;
|
|
151
|
+
}
|
|
152
|
+
}), [environmentId, setCallback, setShowAuthFlow]);
|
|
153
|
+
return React.useMemo(() => ({ signInWithExternalJwt, verifyWithExternalJwt }), [signInWithExternalJwt, verifyWithExternalJwt]);
|
|
125
154
|
};
|
|
126
155
|
|
|
127
156
|
exports.useExternalAuth = useExternalAuth;
|
|
@@ -5,5 +5,6 @@ type Props = {
|
|
|
5
5
|
};
|
|
6
6
|
export declare const useExternalAuth: () => {
|
|
7
7
|
signInWithExternalJwt: ({ externalUserId, externalJwt, }: Props) => Promise<UserProfile | undefined>;
|
|
8
|
+
verifyWithExternalJwt: ({ externalUserId, externalJwt, }: Props) => Promise<UserProfile | undefined>;
|
|
8
9
|
};
|
|
9
10
|
export {};
|
|
@@ -84,7 +84,7 @@ import '../../../context/SendBalanceContext/SendBalanceContext.js';
|
|
|
84
84
|
import '../../../context/ConnectWithOtpContext/ConnectWithOtpContext.js';
|
|
85
85
|
import '../../../context/ConnectWithOtpContext/constants.js';
|
|
86
86
|
import '../../../context/ReinitializeContext/ReinitializeContextProvider.js';
|
|
87
|
-
import { externalAuthSignin } from '../../../data/api/externalAuth/externalAuth.js';
|
|
87
|
+
import { externalAuthSignin, externalAuthVerify } from '../../../data/api/externalAuth/externalAuth.js';
|
|
88
88
|
|
|
89
89
|
const useExternalAuth = () => {
|
|
90
90
|
const { environmentId, setShowAuthFlow, setCallback } = useInternalDynamicContext();
|
|
@@ -117,7 +117,36 @@ const useExternalAuth = () => {
|
|
|
117
117
|
throw e;
|
|
118
118
|
}
|
|
119
119
|
}), [environmentId, setCallback, setShowAuthFlow]);
|
|
120
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Uses a properly-configured non-Dynamic external JWT and user ID to verify the user in Dynamic.
|
|
122
|
+
* When successful, this should verify the user's access to Dynamic's functionality
|
|
123
|
+
* available to only signed-in users, such as wallet linking, etc.
|
|
124
|
+
*
|
|
125
|
+
* @param {string} props.externalJwt - JWT issued outside of Dynamic
|
|
126
|
+
* @param {string} props.externalUserId - User ID to identify the user outside of Dynamic
|
|
127
|
+
*
|
|
128
|
+
* @returns {UserProfile} - User profile for successfully verified user
|
|
129
|
+
*/
|
|
130
|
+
const verifyWithExternalJwt = useCallback((_b) => __awaiter(void 0, [_b], void 0, function* ({ externalUserId, externalJwt, }) {
|
|
131
|
+
try {
|
|
132
|
+
const userProfile = yield externalAuthVerify({
|
|
133
|
+
environmentId,
|
|
134
|
+
externalJwt,
|
|
135
|
+
});
|
|
136
|
+
setCallback('authSuccess');
|
|
137
|
+
setShowAuthFlow(false);
|
|
138
|
+
return userProfile;
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
dynamicEvents.emit('authFailure', {
|
|
142
|
+
externalUserId,
|
|
143
|
+
option: externalUserId,
|
|
144
|
+
type: 'externalAuth',
|
|
145
|
+
}, { error: e });
|
|
146
|
+
throw e;
|
|
147
|
+
}
|
|
148
|
+
}), [environmentId, setCallback, setShowAuthFlow]);
|
|
149
|
+
return useMemo(() => ({ signInWithExternalJwt, verifyWithExternalJwt }), [signInWithExternalJwt, verifyWithExternalJwt]);
|
|
121
150
|
};
|
|
122
151
|
|
|
123
152
|
export { useExternalAuth };
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
7
|
-
var React = require('react');
|
|
8
7
|
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
8
|
+
require('react');
|
|
9
9
|
require('../../../context/DynamicContext/DynamicContext.cjs');
|
|
10
10
|
require('../../../shared/logger.cjs');
|
|
11
11
|
require('@dynamic-labs/iconic');
|
|
@@ -19,7 +19,7 @@ require('../../../shared/utils/classes/storage/localStorage.cjs');
|
|
|
19
19
|
require('../../../shared/utils/classes/storage/sessionStorage.cjs');
|
|
20
20
|
require('@dynamic-labs/utils');
|
|
21
21
|
require('../../../shared/consts/index.cjs');
|
|
22
|
-
require('../../../events/dynamicEvents.cjs');
|
|
22
|
+
var dynamicEvents = require('../../../events/dynamicEvents.cjs');
|
|
23
23
|
require('../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
24
24
|
require('../../../context/ErrorContext/ErrorContext.cjs');
|
|
25
25
|
var errors = require('../../constants/errors.cjs');
|
|
@@ -92,24 +92,11 @@ require('../../../context/ConnectWithOtpContext/constants.cjs');
|
|
|
92
92
|
require('../../../context/ReinitializeContext/ReinitializeContextProvider.cjs');
|
|
93
93
|
var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.cjs');
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
// it is added to help integrate mfa into the invites flow in dashboard
|
|
97
|
-
// the clean solution is to export our views properly as full React components
|
|
98
|
-
// which will allow us to run the function that we pass to `onMfaCompleteOnce`
|
|
99
|
-
// ourselves
|
|
100
|
-
const listeners = {
|
|
101
|
-
onMfaCompleteOnce: undefined,
|
|
102
|
-
};
|
|
103
|
-
const useMfa = ({ onMfaCompleteOnce, } = {}) => {
|
|
104
|
-
React.useEffect(() => {
|
|
105
|
-
if (onMfaCompleteOnce && !listeners.onMfaCompleteOnce) {
|
|
106
|
-
listeners.onMfaCompleteOnce = onMfaCompleteOnce;
|
|
107
|
-
}
|
|
108
|
-
}, [onMfaCompleteOnce]);
|
|
95
|
+
const useMfa = () => {
|
|
109
96
|
const { completeAuth } = useUserAuth.useUserAuth({});
|
|
110
97
|
const { setDeviceSettings } = MfaSettingsContext.useMfaSettingsContext();
|
|
111
|
-
const { user,
|
|
112
|
-
const verifiedUser = user ||
|
|
98
|
+
const { user, userWithMissingInfo, environmentId } = useInternalDynamicContext.useInternalDynamicContext();
|
|
99
|
+
const verifiedUser = user || userWithMissingInfo;
|
|
113
100
|
const getUserDevices = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
114
101
|
if (!verifiedUser) {
|
|
115
102
|
throw new Error(errors.USER_NOT_LOGGED_IN);
|
|
@@ -147,7 +134,6 @@ const useMfa = ({ onMfaCompleteOnce, } = {}) => {
|
|
|
147
134
|
return { id, secret, uri };
|
|
148
135
|
});
|
|
149
136
|
const authDevice = (code_1, ...args_2) => _tslib.__awaiter(void 0, [code_1, ...args_2], void 0, function* (code, type = sdkApiCore.MFADeviceType.Totp) {
|
|
150
|
-
var _a;
|
|
151
137
|
try {
|
|
152
138
|
if (!verifiedUser) {
|
|
153
139
|
throw new Error(errors.USER_NOT_LOGGED_IN);
|
|
@@ -158,7 +144,6 @@ const useMfa = ({ onMfaCompleteOnce, } = {}) => {
|
|
|
158
144
|
isValid = true;
|
|
159
145
|
}),
|
|
160
146
|
updateJwtFunction: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
161
|
-
var _b;
|
|
162
147
|
const response = yield mfa.authMfaDevice({
|
|
163
148
|
code,
|
|
164
149
|
createMfaToken: {
|
|
@@ -167,9 +152,9 @@ const useMfa = ({ onMfaCompleteOnce, } = {}) => {
|
|
|
167
152
|
environmentId,
|
|
168
153
|
type,
|
|
169
154
|
});
|
|
170
|
-
|
|
155
|
+
dynamicEvents.dynamicEvents.emit('mfaCompletionSuccess', {
|
|
171
156
|
mfaToken: response.mfaToken,
|
|
172
|
-
})
|
|
157
|
+
});
|
|
173
158
|
return {
|
|
174
159
|
isEmailVerificationRequired: false,
|
|
175
160
|
isSmsVerificationRequired: false,
|
|
@@ -182,14 +167,9 @@ const useMfa = ({ onMfaCompleteOnce, } = {}) => {
|
|
|
182
167
|
return isValid;
|
|
183
168
|
}
|
|
184
169
|
catch (error) {
|
|
185
|
-
|
|
170
|
+
dynamicEvents.dynamicEvents.emit('mfaCompletionFailure', { error });
|
|
186
171
|
throw error;
|
|
187
172
|
}
|
|
188
|
-
finally {
|
|
189
|
-
if (listeners.onMfaCompleteOnce) {
|
|
190
|
-
listeners.onMfaCompleteOnce = undefined;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
173
|
});
|
|
194
174
|
const authRecoveryCode = (code) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
195
175
|
if (!verifiedUser) {
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { MFADevice, MFADeviceType } from '@dynamic-labs/sdk-api-core';
|
|
2
|
-
|
|
3
|
-
mfaToken?: string;
|
|
4
|
-
} | undefined, err?: Error | null) => Promise<void> | void;
|
|
5
|
-
export declare const useMfa: ({ onMfaCompleteOnce, }?: {
|
|
6
|
-
onMfaCompleteOnce?: OnMfaComplete;
|
|
7
|
-
}) => {
|
|
2
|
+
export declare const useMfa: () => {
|
|
8
3
|
readonly addDevice: (type?: MFADeviceType) => Promise<{
|
|
9
4
|
id: string;
|
|
10
5
|
secret: string;
|
|
@@ -18,4 +13,3 @@ export declare const useMfa: ({ onMfaCompleteOnce, }?: {
|
|
|
18
13
|
readonly updateUserDevice: (deviceId: string) => Promise<void>;
|
|
19
14
|
readonly verifyDevice: (code: string, type?: MFADeviceType) => Promise<MFADevice>;
|
|
20
15
|
};
|
|
21
|
-
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
3
|
-
import { useEffect } from 'react';
|
|
4
3
|
import { MFADeviceType } from '@dynamic-labs/sdk-api-core';
|
|
4
|
+
import 'react';
|
|
5
5
|
import '../../../context/DynamicContext/DynamicContext.js';
|
|
6
6
|
import '../../../shared/logger.js';
|
|
7
7
|
import '@dynamic-labs/iconic';
|
|
@@ -15,7 +15,7 @@ import '../../../shared/utils/classes/storage/localStorage.js';
|
|
|
15
15
|
import '../../../shared/utils/classes/storage/sessionStorage.js';
|
|
16
16
|
import '@dynamic-labs/utils';
|
|
17
17
|
import '../../../shared/consts/index.js';
|
|
18
|
-
import '../../../events/dynamicEvents.js';
|
|
18
|
+
import { dynamicEvents } from '../../../events/dynamicEvents.js';
|
|
19
19
|
import '../../../context/CaptchaContext/CaptchaContext.js';
|
|
20
20
|
import '../../../context/ErrorContext/ErrorContext.js';
|
|
21
21
|
import { USER_NOT_LOGGED_IN } from '../../constants/errors.js';
|
|
@@ -88,24 +88,11 @@ import '../../../context/ConnectWithOtpContext/constants.js';
|
|
|
88
88
|
import '../../../context/ReinitializeContext/ReinitializeContextProvider.js';
|
|
89
89
|
import { useInternalDynamicContext } from '../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.js';
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
// it is added to help integrate mfa into the invites flow in dashboard
|
|
93
|
-
// the clean solution is to export our views properly as full React components
|
|
94
|
-
// which will allow us to run the function that we pass to `onMfaCompleteOnce`
|
|
95
|
-
// ourselves
|
|
96
|
-
const listeners = {
|
|
97
|
-
onMfaCompleteOnce: undefined,
|
|
98
|
-
};
|
|
99
|
-
const useMfa = ({ onMfaCompleteOnce, } = {}) => {
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
if (onMfaCompleteOnce && !listeners.onMfaCompleteOnce) {
|
|
102
|
-
listeners.onMfaCompleteOnce = onMfaCompleteOnce;
|
|
103
|
-
}
|
|
104
|
-
}, [onMfaCompleteOnce]);
|
|
91
|
+
const useMfa = () => {
|
|
105
92
|
const { completeAuth } = useUserAuth({});
|
|
106
93
|
const { setDeviceSettings } = useMfaSettingsContext();
|
|
107
|
-
const { user,
|
|
108
|
-
const verifiedUser = user ||
|
|
94
|
+
const { user, userWithMissingInfo, environmentId } = useInternalDynamicContext();
|
|
95
|
+
const verifiedUser = user || userWithMissingInfo;
|
|
109
96
|
const getUserDevices = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
97
|
if (!verifiedUser) {
|
|
111
98
|
throw new Error(USER_NOT_LOGGED_IN);
|
|
@@ -143,7 +130,6 @@ const useMfa = ({ onMfaCompleteOnce, } = {}) => {
|
|
|
143
130
|
return { id, secret, uri };
|
|
144
131
|
});
|
|
145
132
|
const authDevice = (code_1, ...args_2) => __awaiter(void 0, [code_1, ...args_2], void 0, function* (code, type = MFADeviceType.Totp) {
|
|
146
|
-
var _a;
|
|
147
133
|
try {
|
|
148
134
|
if (!verifiedUser) {
|
|
149
135
|
throw new Error(USER_NOT_LOGGED_IN);
|
|
@@ -154,7 +140,6 @@ const useMfa = ({ onMfaCompleteOnce, } = {}) => {
|
|
|
154
140
|
isValid = true;
|
|
155
141
|
}),
|
|
156
142
|
updateJwtFunction: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
157
|
-
var _b;
|
|
158
143
|
const response = yield authMfaDevice({
|
|
159
144
|
code,
|
|
160
145
|
createMfaToken: {
|
|
@@ -163,9 +148,9 @@ const useMfa = ({ onMfaCompleteOnce, } = {}) => {
|
|
|
163
148
|
environmentId,
|
|
164
149
|
type,
|
|
165
150
|
});
|
|
166
|
-
|
|
151
|
+
dynamicEvents.emit('mfaCompletionSuccess', {
|
|
167
152
|
mfaToken: response.mfaToken,
|
|
168
|
-
})
|
|
153
|
+
});
|
|
169
154
|
return {
|
|
170
155
|
isEmailVerificationRequired: false,
|
|
171
156
|
isSmsVerificationRequired: false,
|
|
@@ -178,14 +163,9 @@ const useMfa = ({ onMfaCompleteOnce, } = {}) => {
|
|
|
178
163
|
return isValid;
|
|
179
164
|
}
|
|
180
165
|
catch (error) {
|
|
181
|
-
|
|
166
|
+
dynamicEvents.emit('mfaCompletionFailure', { error });
|
|
182
167
|
throw error;
|
|
183
168
|
}
|
|
184
|
-
finally {
|
|
185
|
-
if (listeners.onMfaCompleteOnce) {
|
|
186
|
-
listeners.onMfaCompleteOnce = undefined;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
169
|
});
|
|
190
170
|
const authRecoveryCode = (code) => __awaiter(void 0, void 0, void 0, function* () {
|
|
191
171
|
if (!verifiedUser) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useResetCookieLocalStorage } from './useResetCookieLocalStorage';
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
9
|
+
var logger = require('../../../shared/logger.cjs');
|
|
10
|
+
require('@dynamic-labs/iconic');
|
|
11
|
+
require('@dynamic-labs/wallet-connector-core');
|
|
12
|
+
require('react/jsx-runtime');
|
|
13
|
+
require('../../../context/ViewContext/ViewContext.cjs');
|
|
14
|
+
require('@dynamic-labs/wallet-book');
|
|
15
|
+
require('../../constants/colors.cjs');
|
|
16
|
+
require('../../constants/values.cjs');
|
|
17
|
+
require('../../../shared/utils/classes/storage/localStorage.cjs');
|
|
18
|
+
require('../../../shared/utils/classes/storage/sessionStorage.cjs');
|
|
19
|
+
require('@dynamic-labs/utils');
|
|
20
|
+
require('../../../shared/consts/index.cjs');
|
|
21
|
+
require('@dynamic-labs/multi-wallet');
|
|
22
|
+
require('react-international-phone');
|
|
23
|
+
require('../../../config/ApiEndpoint.cjs');
|
|
24
|
+
var userActions = require('../../../store/actions/userActions/userActions.cjs');
|
|
25
|
+
require('../../../locale/locale.cjs');
|
|
26
|
+
var user = require('../../../data/api/user/user.cjs');
|
|
27
|
+
var isCookieEnabled = require('../../functions/isCookieEnabled/isCookieEnabled.cjs');
|
|
28
|
+
require('@dynamic-labs/store');
|
|
29
|
+
require('../../../events/dynamicEvents.cjs');
|
|
30
|
+
require('../../../context/DynamicContext/DynamicContext.cjs');
|
|
31
|
+
require('../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
32
|
+
require('../../../context/ErrorContext/ErrorContext.cjs');
|
|
33
|
+
require('../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
|
|
34
|
+
require('../../../context/AccountExistsContext/AccountExistsContext.cjs');
|
|
35
|
+
require('../../../context/UserWalletsContext/UserWalletsContext.cjs');
|
|
36
|
+
require('../../../context/VerificationContext/VerificationContext.cjs');
|
|
37
|
+
require('react-dom');
|
|
38
|
+
require('../../../context/WalletContext/WalletContext.cjs');
|
|
39
|
+
require('../useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.cjs');
|
|
40
|
+
require('../../../context/ThemeContext/ThemeContext.cjs');
|
|
41
|
+
require('../useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs');
|
|
42
|
+
require('@dynamic-labs/types');
|
|
43
|
+
require('../../../context/LoadingContext/LoadingContext.cjs');
|
|
44
|
+
require('yup');
|
|
45
|
+
require('../../../context/MockContext/MockContext.cjs');
|
|
46
|
+
require('../../../views/CollectUserDataView/useFields.cjs');
|
|
47
|
+
require('../../../context/FieldsStateContext/FieldsStateContext.cjs');
|
|
48
|
+
require('../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
|
|
49
|
+
require('@dynamic-labs/rpc-providers');
|
|
50
|
+
require('react-i18next');
|
|
51
|
+
require('../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
|
|
52
|
+
require('../../../components/Alert/Alert.cjs');
|
|
53
|
+
require('../../../components/ShadowDOM/ShadowDOM.cjs');
|
|
54
|
+
require('../../../components/IconButton/IconButton.cjs');
|
|
55
|
+
require('../../../components/InlineWidget/InlineWidget.cjs');
|
|
56
|
+
require('../../../components/Input/Input.cjs');
|
|
57
|
+
require('../../../components/IsBrowser/IsBrowser.cjs');
|
|
58
|
+
require('../../../components/MenuList/Dropdown/Dropdown.cjs');
|
|
59
|
+
require('../../../components/Transition/ZoomTransition/ZoomTransition.cjs');
|
|
60
|
+
require('../../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
|
|
61
|
+
require('../../../components/Transition/OpacityTransition/OpacityTransition.cjs');
|
|
62
|
+
require('../../../components/OverlayCard/OverlayCardTarget/OverlayCardTarget.cjs');
|
|
63
|
+
require('../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs');
|
|
64
|
+
require('../../../components/Popper/Popper/Popper.cjs');
|
|
65
|
+
require('../../../components/Popper/PopperContext/PopperContext.cjs');
|
|
66
|
+
require('react-focus-lock');
|
|
67
|
+
require('qrcode');
|
|
68
|
+
require('formik');
|
|
69
|
+
require('../../../views/WalletList/WalletList.cjs');
|
|
70
|
+
require('../../../context/SocialRedirectContext/SocialRedirectContext.cjs');
|
|
71
|
+
require('../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
|
|
72
|
+
require('@hcaptcha/react-hcaptcha');
|
|
73
|
+
require('../../../context/FooterAnimationContext/index.cjs');
|
|
74
|
+
require('../../../context/WalletGroupContext/WalletGroupContext.cjs');
|
|
75
|
+
require('../../../context/MfaSettingsContext/MfaSettingsContext.cjs');
|
|
76
|
+
require('../../../context/IpConfigurationContext/IpConfigurationContext.cjs');
|
|
77
|
+
require('../../../context/PasskeyContext/PasskeyContext.cjs');
|
|
78
|
+
require('../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
|
|
79
|
+
require('../../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs');
|
|
80
|
+
require('../../../views/TransactionConfirmationView/helpers/transactionErrorMessage.cjs');
|
|
81
|
+
require('../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs');
|
|
82
|
+
require('../../../../polyfills.cjs');
|
|
83
|
+
require('../../../context/ErrorBoundary/ErrorBoundaryBase.cjs');
|
|
84
|
+
require('../../../context/ErrorBoundary/ErrorBoundaryContext.cjs');
|
|
85
|
+
require('../../../widgets/DynamicBridgeWidget/context/DynamicBridgeWidgetContext/DynamicBridgeWidgetContext.cjs');
|
|
86
|
+
require('../../../widgets/DynamicWidget/components/DynamicWidgetCard/DynamicWidgetCard.cjs');
|
|
87
|
+
require('../../../context/WidgetRegistry/WidgetRegistryContextProvider.cjs');
|
|
88
|
+
require('../../../context/FundingContext/FundingContext.cjs');
|
|
89
|
+
require('../../../context/SendBalanceContext/SendBalanceContext.cjs');
|
|
90
|
+
require('../../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs');
|
|
91
|
+
require('../../../context/ConnectWithOtpContext/constants.cjs');
|
|
92
|
+
require('../../../context/ReinitializeContext/ReinitializeContextProvider.cjs');
|
|
93
|
+
|
|
94
|
+
const useResetCookieLocalStorage = ({ environmentId, projectSettings, setPrimaryWalletId, }) => {
|
|
95
|
+
const didRefreshUserRef = React.useRef(false);
|
|
96
|
+
const user$1 = userActions.getUser();
|
|
97
|
+
/**
|
|
98
|
+
* run this effect every time the user or project settings change
|
|
99
|
+
* but not when the process was already done.
|
|
100
|
+
*/
|
|
101
|
+
React.useEffect(() => {
|
|
102
|
+
/**
|
|
103
|
+
* this method is called on refresh of DynamicContext and attempts to refresh local storage
|
|
104
|
+
* when cookies are enabled for the environment.
|
|
105
|
+
* the use case here is when an end user logs in to sub1.example.com and navigates to sub2.example.com.
|
|
106
|
+
* if they are signed in to sub1.example.com with a cookie for `.example.com`, but the LS is specific
|
|
107
|
+
* to sub1, then navigating to sub2 will mean they are not automatically signed in.
|
|
108
|
+
* this method attempts to fetch the user from the backend using the cookie (if aavailable), and if successful,
|
|
109
|
+
* this will ensure local storage is properly set with the user.
|
|
110
|
+
*
|
|
111
|
+
* this will also attempt to set the primaryWalletId, if the last verified credential is a wallet
|
|
112
|
+
* the user might have signed in with a wallet in the other subdomain, but the primary wallet
|
|
113
|
+
* in local storage does not carry over to other subdomains (LS is subdomain-specific),
|
|
114
|
+
* so attempt to set it here.
|
|
115
|
+
*/
|
|
116
|
+
const maybeInitUserRefresh = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
if (!user$1 && isCookieEnabled.isCookieEnabled()) {
|
|
118
|
+
// Disable all next calls to this method
|
|
119
|
+
didRefreshUserRef.current = true;
|
|
120
|
+
try {
|
|
121
|
+
const user$1 = yield user.refreshUserJwt({ environmentId });
|
|
122
|
+
/**
|
|
123
|
+
* attempt to set primary wallet in this subdomain because LS does not
|
|
124
|
+
* carry over between different subdomains, even if the cookie does
|
|
125
|
+
*/
|
|
126
|
+
const lastVerifiedWallet = user$1 === null || user$1 === void 0 ? void 0 : user$1.verifiedCredentials.find((vc) => vc.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.Blockchain &&
|
|
127
|
+
vc.id === user$1.lastVerifiedCredentialId);
|
|
128
|
+
if (lastVerifiedWallet)
|
|
129
|
+
setPrimaryWalletId(lastVerifiedWallet.id);
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
logger.logger.debug('Ignore failed refreshUserJwt in useResetCookieLocalStorage');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
// Ensure this effect only runs once
|
|
137
|
+
if (didRefreshUserRef.current)
|
|
138
|
+
return;
|
|
139
|
+
maybeInitUserRefresh();
|
|
140
|
+
}, [user$1, projectSettings]);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
exports.useResetCookieLocalStorage = useResetCookieLocalStorage;
|
|
@@ -0,0 +1,8 @@
|
|
|
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) => void;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
3
|
+
import { useRef, useEffect } from 'react';
|
|
4
|
+
import { JwtVerifiedCredentialFormatEnum } from '@dynamic-labs/sdk-api-core';
|
|
5
|
+
import { logger } from '../../../shared/logger.js';
|
|
6
|
+
import '@dynamic-labs/iconic';
|
|
7
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
8
|
+
import 'react/jsx-runtime';
|
|
9
|
+
import '../../../context/ViewContext/ViewContext.js';
|
|
10
|
+
import '@dynamic-labs/wallet-book';
|
|
11
|
+
import '../../constants/colors.js';
|
|
12
|
+
import '../../constants/values.js';
|
|
13
|
+
import '../../../shared/utils/classes/storage/localStorage.js';
|
|
14
|
+
import '../../../shared/utils/classes/storage/sessionStorage.js';
|
|
15
|
+
import '@dynamic-labs/utils';
|
|
16
|
+
import '../../../shared/consts/index.js';
|
|
17
|
+
import '@dynamic-labs/multi-wallet';
|
|
18
|
+
import 'react-international-phone';
|
|
19
|
+
import '../../../config/ApiEndpoint.js';
|
|
20
|
+
import { getUser } from '../../../store/actions/userActions/userActions.js';
|
|
21
|
+
import '../../../locale/locale.js';
|
|
22
|
+
import { refreshUserJwt } from '../../../data/api/user/user.js';
|
|
23
|
+
import { isCookieEnabled } from '../../functions/isCookieEnabled/isCookieEnabled.js';
|
|
24
|
+
import '@dynamic-labs/store';
|
|
25
|
+
import '../../../events/dynamicEvents.js';
|
|
26
|
+
import '../../../context/DynamicContext/DynamicContext.js';
|
|
27
|
+
import '../../../context/CaptchaContext/CaptchaContext.js';
|
|
28
|
+
import '../../../context/ErrorContext/ErrorContext.js';
|
|
29
|
+
import '../../../context/AccessDeniedContext/AccessDeniedContext.js';
|
|
30
|
+
import '../../../context/AccountExistsContext/AccountExistsContext.js';
|
|
31
|
+
import '../../../context/UserWalletsContext/UserWalletsContext.js';
|
|
32
|
+
import '../../../context/VerificationContext/VerificationContext.js';
|
|
33
|
+
import 'react-dom';
|
|
34
|
+
import '../../../context/WalletContext/WalletContext.js';
|
|
35
|
+
import '../useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.js';
|
|
36
|
+
import '../../../context/ThemeContext/ThemeContext.js';
|
|
37
|
+
import '../useUserUpdateRequest/useUpdateUser/userFieldsSchema.js';
|
|
38
|
+
import '@dynamic-labs/types';
|
|
39
|
+
import '../../../context/LoadingContext/LoadingContext.js';
|
|
40
|
+
import 'yup';
|
|
41
|
+
import '../../../context/MockContext/MockContext.js';
|
|
42
|
+
import '../../../views/CollectUserDataView/useFields.js';
|
|
43
|
+
import '../../../context/FieldsStateContext/FieldsStateContext.js';
|
|
44
|
+
import '../../../context/UserFieldEditorContext/UserFieldEditorContext.js';
|
|
45
|
+
import '@dynamic-labs/rpc-providers';
|
|
46
|
+
import 'react-i18next';
|
|
47
|
+
import '../../../components/Accordion/components/AccordionItem/AccordionItem.js';
|
|
48
|
+
import '../../../components/Alert/Alert.js';
|
|
49
|
+
import '../../../components/ShadowDOM/ShadowDOM.js';
|
|
50
|
+
import '../../../components/IconButton/IconButton.js';
|
|
51
|
+
import '../../../components/InlineWidget/InlineWidget.js';
|
|
52
|
+
import '../../../components/Input/Input.js';
|
|
53
|
+
import '../../../components/IsBrowser/IsBrowser.js';
|
|
54
|
+
import '../../../components/MenuList/Dropdown/Dropdown.js';
|
|
55
|
+
import '../../../components/Transition/ZoomTransition/ZoomTransition.js';
|
|
56
|
+
import '../../../components/Transition/SlideInUpTransition/SlideInUpTransition.js';
|
|
57
|
+
import '../../../components/Transition/OpacityTransition/OpacityTransition.js';
|
|
58
|
+
import '../../../components/OverlayCard/OverlayCardTarget/OverlayCardTarget.js';
|
|
59
|
+
import '../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.js';
|
|
60
|
+
import '../../../components/Popper/Popper/Popper.js';
|
|
61
|
+
import '../../../components/Popper/PopperContext/PopperContext.js';
|
|
62
|
+
import 'react-focus-lock';
|
|
63
|
+
import 'qrcode';
|
|
64
|
+
import 'formik';
|
|
65
|
+
import '../../../views/WalletList/WalletList.js';
|
|
66
|
+
import '../../../context/SocialRedirectContext/SocialRedirectContext.js';
|
|
67
|
+
import '../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js';
|
|
68
|
+
import '@hcaptcha/react-hcaptcha';
|
|
69
|
+
import '../../../context/FooterAnimationContext/index.js';
|
|
70
|
+
import '../../../context/WalletGroupContext/WalletGroupContext.js';
|
|
71
|
+
import '../../../context/MfaSettingsContext/MfaSettingsContext.js';
|
|
72
|
+
import '../../../context/IpConfigurationContext/IpConfigurationContext.js';
|
|
73
|
+
import '../../../context/PasskeyContext/PasskeyContext.js';
|
|
74
|
+
import '../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.js';
|
|
75
|
+
import '../../../widgets/DynamicWidget/context/DynamicWidgetContext.js';
|
|
76
|
+
import '../../../views/TransactionConfirmationView/helpers/transactionErrorMessage.js';
|
|
77
|
+
import '../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
|
|
78
|
+
import '../../../../polyfills.js';
|
|
79
|
+
import '../../../context/ErrorBoundary/ErrorBoundaryBase.js';
|
|
80
|
+
import '../../../context/ErrorBoundary/ErrorBoundaryContext.js';
|
|
81
|
+
import '../../../widgets/DynamicBridgeWidget/context/DynamicBridgeWidgetContext/DynamicBridgeWidgetContext.js';
|
|
82
|
+
import '../../../widgets/DynamicWidget/components/DynamicWidgetCard/DynamicWidgetCard.js';
|
|
83
|
+
import '../../../context/WidgetRegistry/WidgetRegistryContextProvider.js';
|
|
84
|
+
import '../../../context/FundingContext/FundingContext.js';
|
|
85
|
+
import '../../../context/SendBalanceContext/SendBalanceContext.js';
|
|
86
|
+
import '../../../context/ConnectWithOtpContext/ConnectWithOtpContext.js';
|
|
87
|
+
import '../../../context/ConnectWithOtpContext/constants.js';
|
|
88
|
+
import '../../../context/ReinitializeContext/ReinitializeContextProvider.js';
|
|
89
|
+
|
|
90
|
+
const useResetCookieLocalStorage = ({ environmentId, projectSettings, setPrimaryWalletId, }) => {
|
|
91
|
+
const didRefreshUserRef = useRef(false);
|
|
92
|
+
const user = getUser();
|
|
93
|
+
/**
|
|
94
|
+
* run this effect every time the user or project settings change
|
|
95
|
+
* but not when the process was already done.
|
|
96
|
+
*/
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
/**
|
|
99
|
+
* this method is called on refresh of DynamicContext and attempts to refresh local storage
|
|
100
|
+
* when cookies are enabled for the environment.
|
|
101
|
+
* the use case here is when an end user logs in to sub1.example.com and navigates to sub2.example.com.
|
|
102
|
+
* if they are signed in to sub1.example.com with a cookie for `.example.com`, but the LS is specific
|
|
103
|
+
* to sub1, then navigating to sub2 will mean they are not automatically signed in.
|
|
104
|
+
* this method attempts to fetch the user from the backend using the cookie (if aavailable), and if successful,
|
|
105
|
+
* this will ensure local storage is properly set with the user.
|
|
106
|
+
*
|
|
107
|
+
* this will also attempt to set the primaryWalletId, if the last verified credential is a wallet
|
|
108
|
+
* the user might have signed in with a wallet in the other subdomain, but the primary wallet
|
|
109
|
+
* in local storage does not carry over to other subdomains (LS is subdomain-specific),
|
|
110
|
+
* so attempt to set it here.
|
|
111
|
+
*/
|
|
112
|
+
const maybeInitUserRefresh = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
if (!user && isCookieEnabled()) {
|
|
114
|
+
// Disable all next calls to this method
|
|
115
|
+
didRefreshUserRef.current = true;
|
|
116
|
+
try {
|
|
117
|
+
const user = yield refreshUserJwt({ environmentId });
|
|
118
|
+
/**
|
|
119
|
+
* attempt to set primary wallet in this subdomain because LS does not
|
|
120
|
+
* carry over between different subdomains, even if the cookie does
|
|
121
|
+
*/
|
|
122
|
+
const lastVerifiedWallet = user === null || user === void 0 ? void 0 : user.verifiedCredentials.find((vc) => vc.format === JwtVerifiedCredentialFormatEnum.Blockchain &&
|
|
123
|
+
vc.id === user.lastVerifiedCredentialId);
|
|
124
|
+
if (lastVerifiedWallet)
|
|
125
|
+
setPrimaryWalletId(lastVerifiedWallet.id);
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
logger.debug('Ignore failed refreshUserJwt in useResetCookieLocalStorage');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
// Ensure this effect only runs once
|
|
133
|
+
if (didRefreshUserRef.current)
|
|
134
|
+
return;
|
|
135
|
+
maybeInitUserRefresh();
|
|
136
|
+
}, [user, projectSettings]);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export { useResetCookieLocalStorage };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSyncMfaFlow } from './useSyncMfaFlow';
|