@dynamic-labs/sdk-react-core 2.1.0-alpha.17 → 2.1.0-alpha.19

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.
Files changed (99) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/package.cjs +2 -2
  3. package/package.js +2 -2
  4. package/package.json +13 -13
  5. package/src/lib/components/MfaRecoveryIcon/MfaRecoveryIcon.cjs +15 -0
  6. package/src/lib/components/MfaRecoveryIcon/MfaRecoveryIcon.d.ts +2 -0
  7. package/src/lib/components/MfaRecoveryIcon/MfaRecoveryIcon.js +11 -0
  8. package/src/lib/components/MfaRecoveryIcon/index.d.ts +1 -0
  9. package/src/lib/components/Portal/Portal.cjs +0 -1
  10. package/src/lib/components/Portal/Portal.js +0 -1
  11. package/src/lib/components/SocialSignIn/SocialSignIn.cjs +5 -2
  12. package/src/lib/components/SocialSignIn/SocialSignIn.js +5 -2
  13. package/src/lib/components/SyncEmbeddedWalletAuthFlow/SyncEmbeddedWalletAuthFlow.cjs +16 -28
  14. package/src/lib/components/SyncEmbeddedWalletAuthFlow/SyncEmbeddedWalletAuthFlow.js +16 -28
  15. package/src/lib/components/UserProfile/parts/UserProfileField/UserProfileField.d.ts +1 -1
  16. package/src/lib/components/index.d.ts +1 -0
  17. package/src/lib/context/DynamicContext/DynamicContext.cjs +1 -1
  18. package/src/lib/context/DynamicContext/DynamicContext.js +1 -1
  19. package/src/lib/context/DynamicContext/hooks/useNameService/useNameService.cjs +4 -5
  20. package/src/lib/context/DynamicContext/hooks/useNameService/useNameService.d.ts +3 -2
  21. package/src/lib/context/DynamicContext/hooks/useNameService/useNameService.js +4 -5
  22. package/src/lib/context/PasskeyContext/PasskeyContext.cjs +1 -1
  23. package/src/lib/context/PasskeyContext/PasskeyContext.js +2 -2
  24. package/src/lib/context/ViewContext/types/index.d.ts +1 -1
  25. package/src/lib/data/api/api.cjs +2 -2
  26. package/src/lib/data/api/api.js +2 -2
  27. package/src/lib/data/api/user/user.cjs +3 -0
  28. package/src/lib/data/api/user/user.js +4 -1
  29. package/src/lib/locale/en/translation.cjs +38 -21
  30. package/src/lib/locale/en/translation.d.ts +38 -21
  31. package/src/lib/locale/en/translation.js +38 -21
  32. package/src/lib/modals/SignMessageConfirmationModal/getProperErrorMessage.cjs +19 -2
  33. package/src/lib/modals/SignMessageConfirmationModal/getProperErrorMessage.js +19 -2
  34. package/src/lib/shared/assets/index.d.ts +1 -0
  35. package/src/lib/shared/assets/mfa-recovery-icon.cjs +54 -0
  36. package/src/lib/shared/assets/mfa-recovery-icon.js +30 -0
  37. package/src/lib/shared/utils/functions/lastAuthenticatedAccount/index.d.ts +2 -2
  38. package/src/lib/shared/utils/functions/wallet/createWallet.d.ts +4 -0
  39. package/src/lib/styles/index.shadow.cjs +1 -1
  40. package/src/lib/styles/index.shadow.js +1 -1
  41. package/src/lib/utils/functions/createUserProfile/createUserProfile.cjs +1 -1
  42. package/src/lib/utils/functions/createUserProfile/createUserProfile.d.ts +2 -1
  43. package/src/lib/utils/functions/createUserProfile/createUserProfile.js +1 -1
  44. package/src/lib/utils/functions/getEnabledSocialSignInProvidersAsProviderEnum/getEnabledSocialSignInProvidersAsProviderEnum.cjs +21 -0
  45. package/src/lib/utils/functions/getEnabledSocialSignInProvidersAsProviderEnum/getEnabledSocialSignInProvidersAsProviderEnum.js +17 -0
  46. package/src/lib/utils/functions/getUserProfileFields/getUserProfileFields.cjs +6 -3
  47. package/src/lib/utils/functions/getUserProfileFields/getUserProfileFields.d.ts +2 -1
  48. package/src/lib/utils/functions/getUserProfileFields/getUserProfileFields.js +7 -4
  49. package/src/lib/utils/functions/validateMfaRecoveryCode/index.d.ts +1 -0
  50. package/src/lib/utils/functions/validateMfaRecoveryCode/validateMfaRecoveryCode.cjs +11 -0
  51. package/src/lib/utils/functions/validateMfaRecoveryCode/validateMfaRecoveryCode.d.ts +1 -0
  52. package/src/lib/utils/functions/validateMfaRecoveryCode/validateMfaRecoveryCode.js +7 -0
  53. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +5 -3
  54. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +5 -3
  55. package/src/lib/utils/hooks/useDynamicLayoutData/useDynamicLayoutData.cjs +8 -0
  56. package/src/lib/utils/hooks/useDynamicLayoutData/useDynamicLayoutData.js +8 -0
  57. package/src/lib/utils/hooks/useDynamicModals/useDynamicModals.cjs +10 -1
  58. package/src/lib/utils/hooks/useDynamicModals/useDynamicModals.d.ts +5 -0
  59. package/src/lib/utils/hooks/useDynamicModals/useDynamicModals.js +10 -1
  60. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.cjs +21 -1
  61. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.d.ts +1 -0
  62. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +21 -1
  63. package/src/lib/utils/hooks/useKYCFlag/useKYCFlag.cjs +1 -0
  64. package/src/lib/utils/hooks/useKYCFlag/useKYCFlag.js +1 -0
  65. package/src/lib/utils/hooks/useMfaModals/index.d.ts +1 -0
  66. package/src/lib/utils/hooks/useMfaModals/useMfaModals.cjs +131 -0
  67. package/src/lib/utils/hooks/useMfaModals/useMfaModals.d.ts +8 -0
  68. package/src/lib/utils/hooks/useMfaModals/useMfaModals.js +127 -0
  69. package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.cjs +24 -3
  70. package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.d.ts +1 -0
  71. package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.js +24 -3
  72. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.cjs +8 -4
  73. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.d.ts +3 -3
  74. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.js +8 -4
  75. package/src/lib/utils/hooks/useUserAuth/useUserAuth.cjs +42 -35
  76. package/src/lib/utils/hooks/useUserAuth/useUserAuth.js +43 -36
  77. package/src/lib/utils/hooks/useUserUpdateRequest/useUpdateUser/useUpdateUser.cjs +7 -2
  78. package/src/lib/utils/hooks/useUserUpdateRequest/useUpdateUser/useUpdateUser.js +7 -2
  79. package/src/lib/views/EmailVerification/EmailVerification.cjs +1 -10
  80. package/src/lib/views/EmailVerification/EmailVerification.js +1 -10
  81. package/src/lib/views/FarcasterQrCodeView/FarcasterQrCodeView.cjs +1 -1
  82. package/src/lib/views/FarcasterQrCodeView/FarcasterQrCodeView.js +1 -1
  83. package/src/lib/views/LoginView/sections/SocialSignInSection/DynamicSocialSignIn/DynamicSocialSignIn.cjs +5 -2
  84. package/src/lib/views/LoginView/sections/SocialSignInSection/DynamicSocialSignIn/DynamicSocialSignIn.js +5 -2
  85. package/src/lib/views/MfaRecoveryView/MfaRecoveryView.cjs +116 -0
  86. package/src/lib/views/MfaRecoveryView/MfaRecoveryView.d.ts +2 -0
  87. package/src/lib/views/MfaRecoveryView/MfaRecoveryView.js +112 -0
  88. package/src/lib/views/MfaRecoveryView/index.d.ts +1 -0
  89. package/src/lib/views/viewToComponentMap.cjs +2 -2
  90. package/src/lib/views/viewToComponentMap.d.ts +2 -2
  91. package/src/lib/views/viewToComponentMap.js +2 -2
  92. package/src/lib/widgets/DynamicBridgeWidget/views/ProfileView/ProfileView.cjs +5 -1
  93. package/src/lib/widgets/DynamicBridgeWidget/views/ProfileView/ProfileView.js +5 -1
  94. package/src/lib/widgets/DynamicWidget/prompts/PendingConnectionModal/PendingConnectionModal.cjs +3 -3
  95. package/src/lib/widgets/DynamicWidget/prompts/PendingConnectionModal/PendingConnectionModal.js +3 -3
  96. package/src/lib/views/EmailUpdate/EmailUpdate.cjs +0 -131
  97. package/src/lib/views/EmailUpdate/EmailUpdate.d.ts +0 -2
  98. package/src/lib/views/EmailUpdate/EmailUpdate.js +0 -127
  99. package/src/lib/views/EmailUpdate/index.d.ts +0 -1
@@ -0,0 +1,127 @@
1
+ 'use client'
2
+ import { useCallback } from 'react';
3
+ import { useViewContext } from '../../../context/ViewContext/ViewContext.js';
4
+ import '../../../context/DynamicContext/DynamicContext.js';
5
+ import '@dynamic-labs/sdk-api-core';
6
+ import '../../../shared/logger.js';
7
+ import '@dynamic-labs/iconic';
8
+ import '@dynamic-labs/wallet-connector-core';
9
+ import 'react/jsx-runtime';
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 '@dynamic-labs/utils';
15
+ import '../../../shared/consts/index.js';
16
+ import '../../../events/dynamicEvents.js';
17
+ import '../../../../../_virtual/_tslib.js';
18
+ import '../../../context/CaptchaContext/CaptchaContext.js';
19
+ import '../../../context/ErrorContext/ErrorContext.js';
20
+ import '@dynamic-labs/multi-wallet';
21
+ import 'react-international-phone';
22
+ import 'viem';
23
+ import 'viem/chains';
24
+ import '../../../config/ApiEndpoint.js';
25
+ import '../../../locale/locale.js';
26
+ import '../../../context/AccessDeniedContext/AccessDeniedContext.js';
27
+ import '../../../context/AccountExistsContext/AccountExistsContext.js';
28
+ import '../../../context/UserWalletsContext/UserWalletsContext.js';
29
+ import '../../../context/VerificationContext/VerificationContext.js';
30
+ import 'react-dom';
31
+ import '../../../context/WalletContext/WalletContext.js';
32
+ import '../../../context/ThemeContext/ThemeContext.js';
33
+ import '@dynamic-labs/types';
34
+ import '../../../context/LoadingContext/LoadingContext.js';
35
+ import 'yup';
36
+ import '../../../context/MockContext/MockContext.js';
37
+ import 'react-i18next';
38
+ import '../../../context/FieldsStateContext/FieldsStateContext.js';
39
+ import '../useUserUpdateRequest/useUpdateUser/useUpdateUser.js';
40
+ import '../../../context/UserFieldEditorContext/UserFieldEditorContext.js';
41
+ import '@dynamic-labs/rpc-providers';
42
+ import '../../../components/Alert/Alert.js';
43
+ import '../../../components/ShadowDOM/ShadowDOM.js';
44
+ import '../../../components/IconButton/IconButton.js';
45
+ import '../../../components/InlineWidget/InlineWidget.js';
46
+ import '../../../components/Input/Input.js';
47
+ import '../../../components/IsBrowser/IsBrowser.js';
48
+ import '../../../components/MenuList/Dropdown/Dropdown.js';
49
+ import '../../../components/Transition/ZoomTransition/ZoomTransition.js';
50
+ import '../../../components/Transition/SlideInUpTransition/SlideInUpTransition.js';
51
+ import '../../../components/Transition/OpacityTransition/OpacityTransition.js';
52
+ import '../../../components/OverlayCard/OverlayCardTarget/OverlayCardTarget.js';
53
+ import '../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.js';
54
+ import '../../../components/Popper/Popper/Popper.js';
55
+ import '../../../components/Popper/PopperContext/PopperContext.js';
56
+ import 'react-focus-lock';
57
+ import 'qrcode';
58
+ import 'formik';
59
+ import '../../../views/WalletList/WalletList.js';
60
+ import '../../../context/SocialRedirectContext/SocialRedirectContext.js';
61
+ import '../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js';
62
+ import '@hcaptcha/react-hcaptcha';
63
+ import '../../../context/FooterAnimationContext/index.js';
64
+ import '../../../views/LoginView/sections/PhoneNumberSignInSection/PhoneNumberSignInSection.js';
65
+ import '../../../context/WalletGroupContext/WalletGroupContext.js';
66
+ import '../../../context/PasskeyContext/PasskeyContext.js';
67
+ import '../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.js';
68
+ import '../../../widgets/DynamicWidget/context/DynamicWidgetContext.js';
69
+ import '../../../views/TransactionConfirmationView/helpers/transactionErrorMessage.js';
70
+ import '../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
71
+ import { useInternalDynamicContext } from '../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.js';
72
+
73
+ const useMfaModals = () => {
74
+ var _a;
75
+ const { setShowAuthFlow, projectSettings } = useInternalDynamicContext();
76
+ const { setView } = useViewContext();
77
+ const isMfaEnabled = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.security.mfa) === null || _a === void 0 ? void 0 : _a.enabled;
78
+ const setShowMfaChooseType = useCallback((value) => {
79
+ if (value) {
80
+ if (!isMfaEnabled)
81
+ return;
82
+ setView('mfa-choose-device');
83
+ }
84
+ setShowAuthFlow(value, { emitCancelAuth: true });
85
+ }, [isMfaEnabled, setShowAuthFlow, setView]);
86
+ const setShowMfaQRCode = useCallback((value) => {
87
+ if (value) {
88
+ if (!isMfaEnabled)
89
+ return;
90
+ setView('mfa-secure-device');
91
+ }
92
+ setShowAuthFlow(value, { emitCancelAuth: true });
93
+ }, [isMfaEnabled, setShowAuthFlow, setView]);
94
+ const setShowOTPVerification = useCallback((value) => {
95
+ if (value) {
96
+ if (!isMfaEnabled)
97
+ return;
98
+ setView('mfa-verification');
99
+ }
100
+ setShowAuthFlow(value, { emitCancelAuth: true });
101
+ }, [isMfaEnabled, setShowAuthFlow, setView]);
102
+ const setShowMfaViewBackupCodes = useCallback((value) => {
103
+ if (value) {
104
+ if (!isMfaEnabled)
105
+ return;
106
+ setView('mfa-display-backup-codes');
107
+ }
108
+ setShowAuthFlow(value, { emitCancelAuth: true });
109
+ }, [isMfaEnabled, setShowAuthFlow, setView]);
110
+ const setShowMfaEnterBackupCodes = useCallback((value) => {
111
+ if (value) {
112
+ if (!isMfaEnabled)
113
+ return;
114
+ setView('mfa-recovery');
115
+ }
116
+ setShowAuthFlow(value, { emitCancelAuth: true });
117
+ }, [isMfaEnabled, setShowAuthFlow, setView]);
118
+ return {
119
+ setShowMfaChooseType,
120
+ setShowMfaEnterBackupCodes,
121
+ setShowMfaQRCode,
122
+ setShowMfaViewBackupCodes,
123
+ setShowOTPVerification,
124
+ };
125
+ };
126
+
127
+ export { useMfaModals };
@@ -26,6 +26,7 @@ require('../../../context/ErrorContext/ErrorContext.cjs');
26
26
  require('@dynamic-labs/multi-wallet');
27
27
  require('react-international-phone');
28
28
  var index = require('../../functions/getEnabledOAuthProviders/index.cjs');
29
+ var getEnabledSocialSignInProvidersAsProviderEnum = require('../../functions/getEnabledSocialSignInProvidersAsProviderEnum/getEnabledSocialSignInProvidersAsProviderEnum.cjs');
29
30
  var isSocialKycEnabled = require('../../functions/isSocialKycEnabled/isSocialKycEnabled.cjs');
30
31
  require('viem');
31
32
  require('viem/chains');
@@ -88,11 +89,9 @@ const useSocialAccounts = ({ sessionTimeout } = {
88
89
  const { setView } = ViewContext.useViewContext();
89
90
  const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback.useUpdateUserProfileByJWTCallback();
90
91
  const { handleError, setError, setIsProcessing, checkValidProvider, error, isProcessing, connectSocialAccount, } = useSocialAuth.useSocialAuth({
91
- authMode: 'link',
92
92
  onFarcasterUrl: (url) => setView('farcaster-connect-view', { url }),
93
93
  sessionTimeout,
94
94
  });
95
- const oauthProviders = index.getEnabledOAuthProviders(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
96
95
  const verifiedOAuthCredentialsMap = React.useMemo(() => {
97
96
  var _a, _b;
98
97
  const verifiedOAuthCredential = (_b = (_a = user === null || user === void 0 ? void 0 : user.verifiedCredentials) === null || _a === void 0 ? void 0 : _a.filter((credential) => credential.format === 'oauth')) !== null && _b !== void 0 ? _b : [];
@@ -114,6 +113,7 @@ const useSocialAccounts = ({ sessionTimeout } = {
114
113
  handleError(types.SocialOAuthErrorCode.ACCOUNT_ALREADY_LINKED, `Account already linked for provider: ${provider}`);
115
114
  return false;
116
115
  }
116
+ const oauthProviders = index.getEnabledOAuthProviders(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
117
117
  const oauthProvider = oauthProviders.find((p) => p.provider === provider);
118
118
  if (!oauthProvider) {
119
119
  handleError(types.SocialOAuthErrorCode.PROVIDER_NOT_ENABLED, `Provider is not enabled on the dashboard: ${provider}`);
@@ -122,7 +122,11 @@ const useSocialAccounts = ({ sessionTimeout } = {
122
122
  return true;
123
123
  };
124
124
  const linkSocialAccount = (provider) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
125
- connectSocialAccount({ provider, validator: checkValidOAuthLinking });
125
+ connectSocialAccount({
126
+ authMode: 'link',
127
+ provider,
128
+ validator: checkValidOAuthLinking,
129
+ });
126
130
  });
127
131
  const unlinkSocialAccount = (provider) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
128
132
  var _a;
@@ -172,12 +176,29 @@ const useSocialAccounts = ({ sessionTimeout } = {
172
176
  username: oauthUsername,
173
177
  };
174
178
  };
179
+ const checkValidOAuthSignIn = (provider) => {
180
+ var _a;
181
+ const oauthProvider = getEnabledSocialSignInProvidersAsProviderEnum.getEnabledSocialSignInProvidersAsProviderEnum((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.socialSignIn) === null || _a === void 0 ? void 0 : _a.providers).find((socialProvider) => socialProvider === provider);
182
+ if (!oauthProvider) {
183
+ handleError(types.SocialOAuthErrorCode.PROVIDER_NOT_ENABLED, `Provider is not enabled for sign-in on the dashboard: ${provider}`);
184
+ return false;
185
+ }
186
+ return true;
187
+ };
188
+ const signInWithSocialAccount = (provider) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
189
+ connectSocialAccount({
190
+ authMode: 'signin',
191
+ provider,
192
+ validator: checkValidOAuthSignIn,
193
+ });
194
+ });
175
195
  return {
176
196
  error,
177
197
  getLinkedAccountInformation,
178
198
  isLinked,
179
199
  isProcessing,
180
200
  linkSocialAccount,
201
+ signInWithSocialAccount,
181
202
  unlinkSocialAccount,
182
203
  };
183
204
  };
@@ -9,6 +9,7 @@ export declare const useSocialAccounts: ({ sessionTimeout }?: UseSocialAccountsP
9
9
  readonly isLinked: (provider: ProviderEnum) => boolean;
10
10
  readonly isProcessing: boolean;
11
11
  readonly linkSocialAccount: (provider: ProviderEnum) => Promise<void>;
12
+ readonly signInWithSocialAccount: (provider: ProviderEnum) => Promise<void>;
12
13
  readonly unlinkSocialAccount: (provider: ProviderEnum) => Promise<void>;
13
14
  };
14
15
  export {};
@@ -22,6 +22,7 @@ import '../../../context/ErrorContext/ErrorContext.js';
22
22
  import '@dynamic-labs/multi-wallet';
23
23
  import 'react-international-phone';
24
24
  import { getEnabledOAuthProviders } from '../../functions/getEnabledOAuthProviders/index.js';
25
+ import { getEnabledSocialSignInProvidersAsProviderEnum } from '../../functions/getEnabledSocialSignInProvidersAsProviderEnum/getEnabledSocialSignInProvidersAsProviderEnum.js';
25
26
  import { isSocialKycEnabled } from '../../functions/isSocialKycEnabled/isSocialKycEnabled.js';
26
27
  import 'viem';
27
28
  import 'viem/chains';
@@ -84,11 +85,9 @@ const useSocialAccounts = ({ sessionTimeout } = {
84
85
  const { setView } = useViewContext();
85
86
  const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback();
86
87
  const { handleError, setError, setIsProcessing, checkValidProvider, error, isProcessing, connectSocialAccount, } = useSocialAuth({
87
- authMode: 'link',
88
88
  onFarcasterUrl: (url) => setView('farcaster-connect-view', { url }),
89
89
  sessionTimeout,
90
90
  });
91
- const oauthProviders = getEnabledOAuthProviders(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
92
91
  const verifiedOAuthCredentialsMap = useMemo(() => {
93
92
  var _a, _b;
94
93
  const verifiedOAuthCredential = (_b = (_a = user === null || user === void 0 ? void 0 : user.verifiedCredentials) === null || _a === void 0 ? void 0 : _a.filter((credential) => credential.format === 'oauth')) !== null && _b !== void 0 ? _b : [];
@@ -110,6 +109,7 @@ const useSocialAccounts = ({ sessionTimeout } = {
110
109
  handleError(SocialOAuthErrorCode.ACCOUNT_ALREADY_LINKED, `Account already linked for provider: ${provider}`);
111
110
  return false;
112
111
  }
112
+ const oauthProviders = getEnabledOAuthProviders(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
113
113
  const oauthProvider = oauthProviders.find((p) => p.provider === provider);
114
114
  if (!oauthProvider) {
115
115
  handleError(SocialOAuthErrorCode.PROVIDER_NOT_ENABLED, `Provider is not enabled on the dashboard: ${provider}`);
@@ -118,7 +118,11 @@ const useSocialAccounts = ({ sessionTimeout } = {
118
118
  return true;
119
119
  };
120
120
  const linkSocialAccount = (provider) => __awaiter(void 0, void 0, void 0, function* () {
121
- connectSocialAccount({ provider, validator: checkValidOAuthLinking });
121
+ connectSocialAccount({
122
+ authMode: 'link',
123
+ provider,
124
+ validator: checkValidOAuthLinking,
125
+ });
122
126
  });
123
127
  const unlinkSocialAccount = (provider) => __awaiter(void 0, void 0, void 0, function* () {
124
128
  var _a;
@@ -168,12 +172,29 @@ const useSocialAccounts = ({ sessionTimeout } = {
168
172
  username: oauthUsername,
169
173
  };
170
174
  };
175
+ const checkValidOAuthSignIn = (provider) => {
176
+ var _a;
177
+ const oauthProvider = getEnabledSocialSignInProvidersAsProviderEnum((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.socialSignIn) === null || _a === void 0 ? void 0 : _a.providers).find((socialProvider) => socialProvider === provider);
178
+ if (!oauthProvider) {
179
+ handleError(SocialOAuthErrorCode.PROVIDER_NOT_ENABLED, `Provider is not enabled for sign-in on the dashboard: ${provider}`);
180
+ return false;
181
+ }
182
+ return true;
183
+ };
184
+ const signInWithSocialAccount = (provider) => __awaiter(void 0, void 0, void 0, function* () {
185
+ connectSocialAccount({
186
+ authMode: 'signin',
187
+ provider,
188
+ validator: checkValidOAuthSignIn,
189
+ });
190
+ });
171
191
  return {
172
192
  error,
173
193
  getLinkedAccountInformation,
174
194
  isLinked,
175
195
  isProcessing,
176
196
  linkSocialAccount,
197
+ signInWithSocialAccount,
177
198
  unlinkSocialAccount,
178
199
  };
179
200
  };
@@ -101,7 +101,7 @@ const socialProviders = [
101
101
  const providersRequiringPkce = ['twitter', 'github'];
102
102
  const providersWithoutWindowOpenerRefence = ['twitter'];
103
103
  // Hook to handle common social auth logic (for social linking and social sign in)
104
- const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, onFarcasterUrl, }) => {
104
+ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, }) => {
105
105
  const { environmentId, setShowAuthFlow, projectSettings, consumeNonce, redirectUrl, } = useInternalDynamicContext.useInternalDynamicContext();
106
106
  const { setErrorMessage, setError: setContextError } = ErrorContext.useErrorContext();
107
107
  const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback.useUpdateUserProfileByJWTCallback();
@@ -180,11 +180,15 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, onFarcast
180
180
  verifyFunction: () => apiCall(),
181
181
  });
182
182
  });
183
- const connectSocialAccount = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ provider, validator, captchaToken, }) {
183
+ const connectSocialAccount = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ authMode, provider, validator, captchaToken, }) {
184
184
  var _b, _c;
185
185
  clearInterval(authWindowInterval.current);
186
186
  clearError();
187
187
  setIsProcessing(true);
188
+ if (!authMode) {
189
+ logger.logger.error('Auth mode is required. Please use either "link" or "signin"');
190
+ return;
191
+ }
188
192
  if (!checkValidProvider(provider)) {
189
193
  return;
190
194
  }
@@ -193,7 +197,7 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, onFarcast
193
197
  return;
194
198
  }
195
199
  if (provider === sdkApiCore.ProviderEnum.Farcaster) {
196
- connectWithFarcaster();
200
+ connectWithFarcaster(authMode);
197
201
  return;
198
202
  }
199
203
  const authWindow = window.open('', '_blank', 'width=500,height=600');
@@ -351,7 +355,7 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, onFarcast
351
355
  }), authWindowTimeout);
352
356
  }
353
357
  });
354
- const connectWithFarcaster = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
358
+ const connectWithFarcaster = (authMode) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
355
359
  const dynamicNonce = consumeNonce();
356
360
  const domain = window.location.host;
357
361
  const data = yield farcaster.connect({
@@ -4,14 +4,14 @@ import { SocialOAuthError, SocialOAuthErrorCode } from '@dynamic-labs/types';
4
4
  type SocialAuthMode = 'link' | 'signin';
5
5
  type UseSocialAuthProps = {
6
6
  sessionTimeout: number;
7
- authMode: SocialAuthMode;
8
7
  onSettled?: () => void;
9
8
  onError?: () => void;
10
9
  onFarcasterUrl?: (url: string) => void;
11
10
  };
12
- export declare const useSocialAuth: ({ sessionTimeout, authMode, onSettled, onError, onFarcasterUrl, }: UseSocialAuthProps) => {
11
+ export declare const useSocialAuth: ({ sessionTimeout, onSettled, onError, onFarcasterUrl, }: UseSocialAuthProps) => {
13
12
  readonly checkValidProvider: (provider: ProviderEnum) => boolean;
14
- readonly connectSocialAccount: ({ provider, validator, captchaToken, }: {
13
+ readonly connectSocialAccount: ({ authMode, provider, validator, captchaToken, }: {
14
+ authMode: SocialAuthMode;
15
15
  provider: ProviderEnum;
16
16
  validator?: (provider: ProviderEnum) => boolean;
17
17
  captchaToken?: string;
@@ -97,7 +97,7 @@ const socialProviders = [
97
97
  const providersRequiringPkce = ['twitter', 'github'];
98
98
  const providersWithoutWindowOpenerRefence = ['twitter'];
99
99
  // Hook to handle common social auth logic (for social linking and social sign in)
100
- const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, onFarcasterUrl, }) => {
100
+ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, }) => {
101
101
  const { environmentId, setShowAuthFlow, projectSettings, consumeNonce, redirectUrl, } = useInternalDynamicContext();
102
102
  const { setErrorMessage, setError: setContextError } = useErrorContext();
103
103
  const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback();
@@ -176,11 +176,15 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, onFarcast
176
176
  verifyFunction: () => apiCall(),
177
177
  });
178
178
  });
179
- const connectSocialAccount = (_a) => __awaiter(void 0, [_a], void 0, function* ({ provider, validator, captchaToken, }) {
179
+ const connectSocialAccount = (_a) => __awaiter(void 0, [_a], void 0, function* ({ authMode, provider, validator, captchaToken, }) {
180
180
  var _b, _c;
181
181
  clearInterval(authWindowInterval.current);
182
182
  clearError();
183
183
  setIsProcessing(true);
184
+ if (!authMode) {
185
+ logger.error('Auth mode is required. Please use either "link" or "signin"');
186
+ return;
187
+ }
184
188
  if (!checkValidProvider(provider)) {
185
189
  return;
186
190
  }
@@ -189,7 +193,7 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, onFarcast
189
193
  return;
190
194
  }
191
195
  if (provider === ProviderEnum.Farcaster) {
192
- connectWithFarcaster();
196
+ connectWithFarcaster(authMode);
193
197
  return;
194
198
  }
195
199
  const authWindow = window.open('', '_blank', 'width=500,height=600');
@@ -347,7 +351,7 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, onFarcast
347
351
  }), authWindowTimeout);
348
352
  }
349
353
  });
350
- const connectWithFarcaster = () => __awaiter(void 0, void 0, void 0, function* () {
354
+ const connectWithFarcaster = (authMode) => __awaiter(void 0, void 0, void 0, function* () {
351
355
  const dynamicNonce = consumeNonce();
352
356
  const domain = window.location.host;
353
357
  const data = yield connect({
@@ -81,15 +81,15 @@ var useInternalDynamicContext = require('../../../context/DynamicContext/useDyna
81
81
 
82
82
  const sleepToShowSuccessMessage = () => utils.sleep(1500);
83
83
  const useUserAuth = ({ authMethod, }) => {
84
- const { handleLogOut, setOnboardingOnlyJwt, setShowAuthFlow, setCallback, onboardingOnlyJwt, setMultiWalletWidgetState, projectSettings, } = useInternalDynamicContext.useInternalDynamicContext();
84
+ const { handleLogOut, setOnboardingOnlyJwt, setShowAuthFlow, setCallback, onboardingOnlyJwt, setMultiWalletWidgetState, } = useInternalDynamicContext.useInternalDynamicContext();
85
85
  const { view, setView, goToInitialView } = ViewContext.useViewContext();
86
86
  const { setLoading } = LoadingContext.useLoadingContext();
87
87
  const { setErrorMessage, setError } = ErrorContext.useErrorContext();
88
88
  const { setExistentAccountData } = AccountExistsContext.useAccountExistsContext();
89
- const { createEmbeddedWallet } = useEmbeddedWallet.useEmbeddedWallet();
90
89
  const { handleVerifiedUserWithJWT } = useHandleVerifiedUser.useHandleVerifiedUser();
91
90
  const { createUserProfileByJWT } = useCreateUserProfileByJWTCallback.useCreateUserProfileByJWTCallback();
92
91
  const { displayedDestination: formattedPhone } = VerificationContext.useVerification();
92
+ const { shouldAutoCreateEmbeddedWallet } = useEmbeddedWallet.useEmbeddedWallet();
93
93
  const initAuth = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ isSignIn = true, verifyFunction, onVerifySuccess, onSettled, onError, showSuccessMessage = false, skipDefaultErrorHandling = false, }) {
94
94
  logger.logger.debug('initAuth', { authMethod, isSignIn });
95
95
  try {
@@ -115,9 +115,13 @@ const useUserAuth = ({ authMethod, }) => {
115
115
  yield createUserProfileByJWT(jwt, minifiedJwt);
116
116
  if (isSignIn) {
117
117
  setCallback('authSuccess');
118
- yield createEmbeddedWalletIfEnabled();
119
118
  }
120
- setShowAuthFlow(false);
119
+ // we should only close auth flow if no wallet is going to be created,
120
+ // otherwise there will be a glitch with auth flow closing and then reopening for passkeys
121
+ const shouldCreateWallet = shouldAutoCreateEmbeddedWallet();
122
+ if (!shouldCreateWallet) {
123
+ setShowAuthFlow(false);
124
+ }
121
125
  onSettled === null || onSettled === void 0 ? void 0 : onSettled();
122
126
  }
123
127
  catch (error) {
@@ -156,22 +160,14 @@ const useUserAuth = ({ authMethod, }) => {
156
160
  }
157
161
  onSettled === null || onSettled === void 0 ? void 0 : onSettled();
158
162
  });
159
- const createEmbeddedWalletIfEnabled = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
160
- var _b, _c;
161
- if (!((_c = (_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _b === void 0 ? void 0 : _b.embeddedWallets) === null || _c === void 0 ? void 0 : _c.automaticEmbeddedWalletCreation)) {
162
- return;
163
- }
164
- try {
165
- // this function will check if embedded wallet is enabled and create wallet if needed
166
- // if not enabled, it will throw an error.
167
- yield createEmbeddedWallet();
168
- }
169
- catch (e) {
170
- logger.logger.debug('createEmbeddedWallet', e);
171
- setShowAuthFlow(false);
172
- }
173
- });
174
163
  const handleError = (error, { options = {}, onError, }) => {
164
+ // these get caught in onboarding form and handled there
165
+ if (error instanceof utils.EmailAlreadyExistsError ||
166
+ error instanceof utils.CustomFieldNotUniqueError ||
167
+ error instanceof utils.UsernameAlreadyExistsError ||
168
+ error instanceof utils.TooManyEmailVerificationsError ||
169
+ error instanceof utils.InvalidPhoneNumberError)
170
+ throw error;
175
171
  if (error instanceof utils.NoAccessError) {
176
172
  setView('no-access');
177
173
  return;
@@ -201,29 +197,35 @@ const useUserAuth = ({ authMethod, }) => {
201
197
  setError(error.message);
202
198
  }
203
199
  };
204
- const completeAuth = (_d) => _tslib.__awaiter(void 0, [_d], void 0, function* ({ completeSignInFlow, updateJwtFunction, onValidUpdatedJwt, options = {}, }) {
200
+ const handleVerifyMissingFields = (_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ missingFields, isEmailVerificationRequired, isSmsVerificationRequired, }) {
201
+ if (isEmailVerificationRequired &&
202
+ missingFields.find((field) => field.name === 'email')) {
203
+ setView('verify-email');
204
+ return;
205
+ }
206
+ if (isSmsVerificationRequired &&
207
+ missingFields.find((field) => field.name === 'phoneNumber')) {
208
+ setView('verify-sms');
209
+ return;
210
+ }
211
+ setView(view.type);
212
+ });
213
+ const completeAuth = (_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ completeSignInFlow, updateJwtFunction, onValidUpdatedJwt, options = {}, }) {
205
214
  logger.logger.debug('completeAuth', { authMethod });
206
215
  try {
207
216
  const { updateUserProfileResponse, isSmsVerificationRequired, isEmailVerificationRequired, missingFields, } = yield updateJwtFunction();
208
217
  onValidUpdatedJwt === null || onValidUpdatedJwt === void 0 ? void 0 : onValidUpdatedJwt();
209
218
  setOnboardingOnlyJwt(updateUserProfileResponse.jwt);
210
219
  localStorage.LocalStorage.setToLS(localStorage$1.AUTH_ONBOARDING_TOKEN, updateUserProfileResponse.minifiedJwt, true);
211
- if (isEmailVerificationRequired &&
212
- missingFields.map((field) => field.name).toString() === 'email') {
213
- setView('verify-email');
214
- return;
215
- }
216
- else if (isSmsVerificationRequired &&
217
- missingFields.map((field) => field.name).toString() === 'phoneNumber') {
218
- setView('verify-sms');
219
- return;
220
- }
221
- else if (missingFields.length > 0) {
222
- // make sure we capture the fields that are required and still missing!
223
- // do not change the view, just use the current one
224
- setView(view.type);
220
+ if (missingFields.length > 0) {
221
+ yield handleVerifyMissingFields({
222
+ isEmailVerificationRequired,
223
+ isSmsVerificationRequired,
224
+ missingFields,
225
+ });
225
226
  return;
226
227
  }
228
+ // no more onboarding needed, clean up onboarding jwt
227
229
  if (onboardingOnlyJwt) {
228
230
  yield handleVerifiedUserWithJWT(updateUserProfileResponse.jwt);
229
231
  setOnboardingOnlyJwt(undefined);
@@ -236,7 +238,12 @@ const useUserAuth = ({ authMethod, }) => {
236
238
  return;
237
239
  }
238
240
  }
239
- yield createEmbeddedWalletIfEnabled();
241
+ // we should only close auth flow if no wallet is going to be created,
242
+ // otherwise there will be a glitch with auth flow closing and then reopening for passkeys
243
+ const shouldCreateWallet = shouldAutoCreateEmbeddedWallet();
244
+ if (!shouldCreateWallet) {
245
+ setShowAuthFlow(false);
246
+ }
240
247
  }
241
248
  catch (error) {
242
249
  logger.logger.debug(error);
@@ -1,6 +1,6 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
- import { DynamicError, NoAccessError, AccountExistsError, UserHasAccountWithEmailError, sleep } from '@dynamic-labs/utils';
3
+ import { DynamicError, EmailAlreadyExistsError, CustomFieldNotUniqueError, UsernameAlreadyExistsError, TooManyEmailVerificationsError, InvalidPhoneNumberError, NoAccessError, AccountExistsError, UserHasAccountWithEmailError, sleep } from '@dynamic-labs/utils';
4
4
  import 'react';
5
5
  import '../../../context/DynamicContext/DynamicContext.js';
6
6
  import { decodeJwt } from '../../../shared/utils/functions/decodeJwt/decodeJwt.js';
@@ -77,15 +77,15 @@ import { useInternalDynamicContext } from '../../../context/DynamicContext/useDy
77
77
 
78
78
  const sleepToShowSuccessMessage = () => sleep(1500);
79
79
  const useUserAuth = ({ authMethod, }) => {
80
- const { handleLogOut, setOnboardingOnlyJwt, setShowAuthFlow, setCallback, onboardingOnlyJwt, setMultiWalletWidgetState, projectSettings, } = useInternalDynamicContext();
80
+ const { handleLogOut, setOnboardingOnlyJwt, setShowAuthFlow, setCallback, onboardingOnlyJwt, setMultiWalletWidgetState, } = useInternalDynamicContext();
81
81
  const { view, setView, goToInitialView } = useViewContext();
82
82
  const { setLoading } = useLoadingContext();
83
83
  const { setErrorMessage, setError } = useErrorContext();
84
84
  const { setExistentAccountData } = useAccountExistsContext();
85
- const { createEmbeddedWallet } = useEmbeddedWallet();
86
85
  const { handleVerifiedUserWithJWT } = useHandleVerifiedUser();
87
86
  const { createUserProfileByJWT } = useCreateUserProfileByJWTCallback();
88
87
  const { displayedDestination: formattedPhone } = useVerification();
88
+ const { shouldAutoCreateEmbeddedWallet } = useEmbeddedWallet();
89
89
  const initAuth = (_a) => __awaiter(void 0, [_a], void 0, function* ({ isSignIn = true, verifyFunction, onVerifySuccess, onSettled, onError, showSuccessMessage = false, skipDefaultErrorHandling = false, }) {
90
90
  logger.debug('initAuth', { authMethod, isSignIn });
91
91
  try {
@@ -111,9 +111,13 @@ const useUserAuth = ({ authMethod, }) => {
111
111
  yield createUserProfileByJWT(jwt, minifiedJwt);
112
112
  if (isSignIn) {
113
113
  setCallback('authSuccess');
114
- yield createEmbeddedWalletIfEnabled();
115
114
  }
116
- setShowAuthFlow(false);
115
+ // we should only close auth flow if no wallet is going to be created,
116
+ // otherwise there will be a glitch with auth flow closing and then reopening for passkeys
117
+ const shouldCreateWallet = shouldAutoCreateEmbeddedWallet();
118
+ if (!shouldCreateWallet) {
119
+ setShowAuthFlow(false);
120
+ }
117
121
  onSettled === null || onSettled === void 0 ? void 0 : onSettled();
118
122
  }
119
123
  catch (error) {
@@ -152,22 +156,14 @@ const useUserAuth = ({ authMethod, }) => {
152
156
  }
153
157
  onSettled === null || onSettled === void 0 ? void 0 : onSettled();
154
158
  });
155
- const createEmbeddedWalletIfEnabled = () => __awaiter(void 0, void 0, void 0, function* () {
156
- var _b, _c;
157
- if (!((_c = (_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _b === void 0 ? void 0 : _b.embeddedWallets) === null || _c === void 0 ? void 0 : _c.automaticEmbeddedWalletCreation)) {
158
- return;
159
- }
160
- try {
161
- // this function will check if embedded wallet is enabled and create wallet if needed
162
- // if not enabled, it will throw an error.
163
- yield createEmbeddedWallet();
164
- }
165
- catch (e) {
166
- logger.debug('createEmbeddedWallet', e);
167
- setShowAuthFlow(false);
168
- }
169
- });
170
159
  const handleError = (error, { options = {}, onError, }) => {
160
+ // these get caught in onboarding form and handled there
161
+ if (error instanceof EmailAlreadyExistsError ||
162
+ error instanceof CustomFieldNotUniqueError ||
163
+ error instanceof UsernameAlreadyExistsError ||
164
+ error instanceof TooManyEmailVerificationsError ||
165
+ error instanceof InvalidPhoneNumberError)
166
+ throw error;
171
167
  if (error instanceof NoAccessError) {
172
168
  setView('no-access');
173
169
  return;
@@ -197,29 +193,35 @@ const useUserAuth = ({ authMethod, }) => {
197
193
  setError(error.message);
198
194
  }
199
195
  };
200
- const completeAuth = (_d) => __awaiter(void 0, [_d], void 0, function* ({ completeSignInFlow, updateJwtFunction, onValidUpdatedJwt, options = {}, }) {
196
+ const handleVerifyMissingFields = (_b) => __awaiter(void 0, [_b], void 0, function* ({ missingFields, isEmailVerificationRequired, isSmsVerificationRequired, }) {
197
+ if (isEmailVerificationRequired &&
198
+ missingFields.find((field) => field.name === 'email')) {
199
+ setView('verify-email');
200
+ return;
201
+ }
202
+ if (isSmsVerificationRequired &&
203
+ missingFields.find((field) => field.name === 'phoneNumber')) {
204
+ setView('verify-sms');
205
+ return;
206
+ }
207
+ setView(view.type);
208
+ });
209
+ const completeAuth = (_c) => __awaiter(void 0, [_c], void 0, function* ({ completeSignInFlow, updateJwtFunction, onValidUpdatedJwt, options = {}, }) {
201
210
  logger.debug('completeAuth', { authMethod });
202
211
  try {
203
212
  const { updateUserProfileResponse, isSmsVerificationRequired, isEmailVerificationRequired, missingFields, } = yield updateJwtFunction();
204
213
  onValidUpdatedJwt === null || onValidUpdatedJwt === void 0 ? void 0 : onValidUpdatedJwt();
205
214
  setOnboardingOnlyJwt(updateUserProfileResponse.jwt);
206
215
  LocalStorage.setToLS(AUTH_ONBOARDING_TOKEN, updateUserProfileResponse.minifiedJwt, true);
207
- if (isEmailVerificationRequired &&
208
- missingFields.map((field) => field.name).toString() === 'email') {
209
- setView('verify-email');
210
- return;
211
- }
212
- else if (isSmsVerificationRequired &&
213
- missingFields.map((field) => field.name).toString() === 'phoneNumber') {
214
- setView('verify-sms');
215
- return;
216
- }
217
- else if (missingFields.length > 0) {
218
- // make sure we capture the fields that are required and still missing!
219
- // do not change the view, just use the current one
220
- setView(view.type);
216
+ if (missingFields.length > 0) {
217
+ yield handleVerifyMissingFields({
218
+ isEmailVerificationRequired,
219
+ isSmsVerificationRequired,
220
+ missingFields,
221
+ });
221
222
  return;
222
223
  }
224
+ // no more onboarding needed, clean up onboarding jwt
223
225
  if (onboardingOnlyJwt) {
224
226
  yield handleVerifiedUserWithJWT(updateUserProfileResponse.jwt);
225
227
  setOnboardingOnlyJwt(undefined);
@@ -232,7 +234,12 @@ const useUserAuth = ({ authMethod, }) => {
232
234
  return;
233
235
  }
234
236
  }
235
- yield createEmbeddedWalletIfEnabled();
237
+ // we should only close auth flow if no wallet is going to be created,
238
+ // otherwise there will be a glitch with auth flow closing and then reopening for passkeys
239
+ const shouldCreateWallet = shouldAutoCreateEmbeddedWallet();
240
+ if (!shouldCreateWallet) {
241
+ setShowAuthFlow(false);
242
+ }
236
243
  }
237
244
  catch (error) {
238
245
  logger.debug(error);