@dynamic-labs/sdk-react-core 0.19.0-alpha.7 → 0.19.0-alpha.8
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 +24 -0
- package/package.cjs +3 -3
- package/package.js +3 -3
- package/package.json +10 -10
- package/src/index.d.ts +1 -1
- package/src/lib/Main.cjs +1 -0
- package/src/lib/Main.js +1 -0
- package/src/lib/components/AuthProviderIcon/AuthProviderIcon.cjs +2 -2
- package/src/lib/components/AuthProviderIcon/AuthProviderIcon.js +2 -2
- package/src/lib/components/IconWithStatus/IconWithStatus.cjs +3 -3
- package/src/lib/components/IconWithStatus/IconWithStatus.d.ts +2 -2
- package/src/lib/components/IconWithStatus/IconWithStatus.js +3 -3
- package/src/lib/components/MockedQrCode/MockedQrCode.cjs +1 -1
- package/src/lib/components/MockedQrCode/MockedQrCode.js +1 -1
- package/src/lib/components/SendBalancePageLayout/SendBalancePageLayout.cjs +2 -2
- package/src/lib/components/SendBalancePageLayout/SendBalancePageLayout.d.ts +1 -1
- package/src/lib/components/SendBalancePageLayout/SendBalancePageLayout.js +2 -2
- package/src/lib/components/SocialSignIn/SocialSignIn.cjs +26 -14
- package/src/lib/components/SocialSignIn/SocialSignIn.d.ts +8 -7
- package/src/lib/components/SocialSignIn/SocialSignIn.js +26 -14
- package/src/lib/components/TransactionOriginDestination/TransactionOriginDestination.d.ts +1 -1
- package/src/lib/components/UserProfile/UserProfile.cjs +4 -1
- package/src/lib/components/UserProfile/UserProfile.js +4 -1
- package/src/lib/components/UserProfile/parts/UserProfileSocialAccount/UserProfileSocialAccount.cjs +15 -13
- package/src/lib/components/UserProfile/parts/UserProfileSocialAccount/UserProfileSocialAccount.js +15 -13
- package/src/lib/context/DynamicContext/helpers.cjs +22 -10
- package/src/lib/context/DynamicContext/helpers.d.ts +4 -2
- package/src/lib/context/DynamicContext/helpers.js +20 -10
- package/src/lib/context/ErrorContext/ErrorContext.cjs +4 -1
- package/src/lib/context/ErrorContext/ErrorContext.js +4 -1
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.cjs +7 -4
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.d.ts +5 -5
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.js +7 -4
- package/src/lib/data/api.cjs +48 -16
- package/src/lib/data/api.d.ts +1 -0
- package/src/lib/data/api.js +50 -19
- package/src/lib/layout/DynamicAuthLayout/HelpContent/WalletListHelpContent/WalletListHelpContent.cjs +1 -1
- package/src/lib/layout/DynamicAuthLayout/HelpContent/WalletListHelpContent/WalletListHelpContent.js +1 -1
- package/src/lib/locale/en/translation.cjs +2 -4
- package/src/lib/locale/en/translation.js +2 -4
- package/src/lib/shared/types/index.d.ts +4 -0
- package/src/lib/shared/utils/functions/wallet/createWallet.cjs +1 -1
- package/src/lib/shared/utils/functions/wallet/createWallet.js +1 -1
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/constants/localStorage.cjs +4 -2
- package/src/lib/utils/constants/localStorage.d.ts +2 -1
- package/src/lib/utils/constants/localStorage.js +3 -2
- package/src/lib/utils/functions/getActiveOauthCredential/getActiveOauthCredential.cjs +11 -0
- package/src/lib/utils/functions/getActiveOauthCredential/getActiveOauthCredential.d.ts +2 -0
- package/src/lib/utils/functions/getActiveOauthCredential/getActiveOauthCredential.js +7 -0
- package/src/lib/utils/functions/getActiveOauthCredential/index.d.ts +1 -0
- package/src/lib/utils/functions/getEnabledSocialSignInProvidersAsProviderEnum/getEnabledSocialSignInProvidersAsProviderEnum.d.ts +2 -0
- package/src/lib/utils/functions/getEnabledSocialSignInProvidersAsProviderEnum/index.d.ts +1 -0
- package/src/lib/utils/functions/getProviderEnumForSocialSignInProvider/getProviderEnumForSocialSignInProvider.cjs +19 -0
- package/src/lib/utils/functions/getProviderEnumForSocialSignInProvider/getProviderEnumForSocialSignInProvider.d.ts +2 -0
- package/src/lib/utils/functions/getProviderEnumForSocialSignInProvider/getProviderEnumForSocialSignInProvider.js +15 -0
- package/src/lib/utils/functions/getProviderEnumForSocialSignInProvider/index.d.ts +1 -0
- package/src/lib/utils/functions/getSocialSignInProviderForProviderEnum/getSocialSignInProviderForProviderEnum.cjs +19 -0
- package/src/lib/utils/functions/getSocialSignInProviderForProviderEnum/getSocialSignInProviderForProviderEnum.d.ts +2 -0
- package/src/lib/utils/functions/getSocialSignInProviderForProviderEnum/getSocialSignInProviderForProviderEnum.js +15 -0
- package/src/lib/utils/functions/getSocialSignInProviderForProviderEnum/index.d.ts +1 -0
- package/src/lib/utils/functions/getSocialSignInProviderFromString/getSocialSignInProviderFromString.cjs +19 -0
- package/src/lib/utils/functions/getSocialSignInProviderFromString/getSocialSignInProviderFromString.d.ts +2 -0
- package/src/lib/utils/functions/getSocialSignInProviderFromString/getSocialSignInProviderFromString.js +15 -0
- package/src/lib/utils/functions/getSocialSignInProviderFromString/index.d.ts +1 -0
- package/src/lib/utils/functions/index.d.ts +5 -0
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +2 -1
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +2 -1
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.cjs +3 -3
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +4 -4
- package/src/lib/utils/hooks/useFetchProjectSettings/useFetchProjectSettings.cjs +10 -1
- package/src/lib/utils/hooks/useFetchProjectSettings/useFetchProjectSettings.js +10 -1
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.cjs +10 -164
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.d.ts +2 -2
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.js +12 -166
- package/src/lib/utils/hooks/useSocialAuth/index.d.ts +1 -0
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.cjs +278 -0
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.d.ts +20 -0
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.js +274 -0
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.cjs +13 -3
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.js +13 -3
- package/src/lib/views/AccountExistsView/AccountExistsView.cjs +4 -2
- package/src/lib/views/AccountExistsView/AccountExistsView.js +4 -2
- package/src/lib/views/BridgeSummaryView/BridgeSummaryView.cjs +1 -1
- package/src/lib/views/BridgeSummaryView/BridgeSummaryView.js +1 -1
- package/src/lib/views/LoginView/LoginView.cjs +1 -1
- package/src/lib/views/LoginView/LoginView.js +1 -1
- package/src/lib/views/LoginView/sections/LoginWidget.d.ts +5 -0
- package/src/lib/views/LoginView/sections/SocialSignInSection/DynamicSocialSignIn/DynamicSocialSignIn.cjs +77 -0
- package/src/lib/views/LoginView/sections/SocialSignInSection/DynamicSocialSignIn/DynamicSocialSignIn.d.ts +3 -0
- package/src/lib/views/LoginView/sections/SocialSignInSection/DynamicSocialSignIn/DynamicSocialSignIn.js +73 -0
- package/src/lib/views/LoginView/sections/SocialSignInSection/DynamicSocialSignIn/index.d.ts +1 -0
- package/src/lib/views/LoginView/sections/SocialSignInSection/MagicSocialSignIn/MagicSocialSignIn.cjs +3 -2
- package/src/lib/views/LoginView/sections/SocialSignInSection/MagicSocialSignIn/MagicSocialSignIn.d.ts +2 -1
- package/src/lib/views/LoginView/sections/SocialSignInSection/MagicSocialSignIn/MagicSocialSignIn.js +3 -2
- package/src/lib/views/LoginView/sections/SocialSignInSection/SocialSignInSection.cjs +18 -4
- package/src/lib/views/LoginView/sections/SocialSignInSection/SocialSignInSection.d.ts +6 -1
- package/src/lib/views/LoginView/sections/SocialSignInSection/SocialSignInSection.js +18 -4
- package/src/lib/views/LoginView/sections/WalletSignInSection/WalletSignInSection.cjs +3 -2
- package/src/lib/views/LoginView/sections/WalletSignInSection/WalletSignInSection.js +3 -2
- package/src/lib/views/LoginView/useLoginView.cjs +9 -10
- package/src/lib/views/LoginView/useLoginView.js +9 -10
- package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.cjs +1 -1
- package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.js +1 -1
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +1 -1
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +1 -1
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.cjs +1 -1
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.js +1 -1
- package/src/lib/views/NoQrNotInstalledView/NoQrNotInstalledView.cjs +2 -2
- package/src/lib/views/NoQrNotInstalledView/NoQrNotInstalledView.js +2 -2
- package/src/lib/views/PendingConnectView/PendingConnectView.cjs +1 -1
- package/src/lib/views/PendingConnectView/PendingConnectView.js +1 -1
- package/src/lib/views/PendingSignatureView/PendingSignatureView.cjs +1 -1
- package/src/lib/views/PendingSignatureView/PendingSignatureView.js +1 -1
- package/src/lib/views/QrCodeView/QRCode.cjs +3 -3
- package/src/lib/views/QrCodeView/QRCode.d.ts +2 -2
- package/src/lib/views/QrCodeView/QRCode.js +3 -3
- package/src/lib/views/QrCodeView/QrCodeContainer/QrCodeContainer.cjs +2 -2
- package/src/lib/views/QrCodeView/QrCodeContainer/QrCodeContainer.d.ts +2 -1
- package/src/lib/views/QrCodeView/QrCodeContainer/QrCodeContainer.js +2 -2
- package/src/lib/views/QrCodeView/QrCodeView.cjs +2 -2
- package/src/lib/views/QrCodeView/QrCodeView.js +2 -2
- package/src/lib/views/SendBalanceView/SendBalanceView.cjs +1 -1
- package/src/lib/views/SendBalanceView/SendBalanceView.js +1 -1
- package/src/lib/views/SocialRedirectView/SocialRedirectView.cjs +4 -6
- package/src/lib/views/SocialRedirectView/SocialRedirectView.d.ts +1 -1
- package/src/lib/views/SocialRedirectView/SocialRedirectView.js +4 -6
- package/src/lib/views/WalletCannotBeTransferredView/WalletCannotBeTransferredView.cjs +1 -1
- package/src/lib/views/WalletCannotBeTransferredView/WalletCannotBeTransferredView.js +1 -1
- package/src/lib/views/WalletGroupView/WalletGroupView.cjs +1 -1
- package/src/lib/views/WalletGroupView/WalletGroupView.js +1 -1
- package/src/lib/views/WalletList/WalletListItem/WalletListItem.cjs +2 -2
- package/src/lib/views/WalletList/WalletListItem/WalletListItem.js +2 -2
- package/src/lib/views/WalletLockedView/WalletLockedView.cjs +1 -1
- package/src/lib/views/WalletLockedView/WalletLockedView.js +1 -1
- package/src/lib/views/WalletSignSpinnerView/WalletSignSpinnerView.cjs +2 -2
- package/src/lib/views/WalletSignSpinnerView/WalletSignSpinnerView.js +2 -2
- package/src/lib/views/WalletUsedView/WalletUsedView.cjs +1 -1
- package/src/lib/views/WalletUsedView/WalletUsedView.js +1 -1
- package/src/lib/widgets/DynamicBridgeWidget/components/DynamicBridgeWalletCardBody/DynamicBridgeWalletCardBody.cjs +2 -2
- package/src/lib/widgets/DynamicBridgeWidget/components/DynamicBridgeWalletCardBody/DynamicBridgeWalletCardBody.d.ts +1 -1
- package/src/lib/widgets/DynamicBridgeWidget/components/DynamicBridgeWalletCardBody/DynamicBridgeWalletCardBody.js +2 -2
- package/src/lib/widgets/DynamicBridgeWidget/views/WalletsView/WalletsView.cjs +1 -1
- package/src/lib/widgets/DynamicBridgeWidget/views/WalletsView/WalletsView.js +1 -1
- package/src/lib/widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs +1 -1
- package/src/lib/widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js +1 -1
- package/src/lib/widgets/DynamicWidget/components/AccountControl/AccountControl.cjs +18 -3
- package/src/lib/widgets/DynamicWidget/components/AccountControl/AccountControl.js +18 -3
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetWalletHeader/DynamicWidgetWalletHeader.cjs +9 -1
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetWalletHeader/DynamicWidgetWalletHeader.d.ts +1 -1
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetWalletHeader/DynamicWidgetWalletHeader.js +9 -1
- package/src/lib/widgets/DynamicWidget/components/WalletIconWithStatus/WalletIconWithStatus.cjs +2 -2
- package/src/lib/widgets/DynamicWidget/components/WalletIconWithStatus/WalletIconWithStatus.d.ts +2 -2
- package/src/lib/widgets/DynamicWidget/components/WalletIconWithStatus/WalletIconWithStatus.js +2 -2
- package/src/lib/widgets/DynamicWidget/prompts/NoQrNotInstalledModalView/NoQrNotInstalledModalView.cjs +3 -3
- package/src/lib/widgets/DynamicWidget/prompts/NoQrNotInstalledModalView/NoQrNotInstalledModalView.js +3 -3
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/PendingAccountSwitchModal.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/PendingAccountSwitchModal.js +1 -1
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/SwitchOrUseActiveAccountView/SwitchOrUseActiveAccountView.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/SwitchOrUseActiveAccountView/SwitchOrUseActiveAccountView.js +1 -1
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchToLinkModal/PendingAccountSwitchToLinkModal.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchToLinkModal/PendingAccountSwitchToLinkModal.js +1 -1
- package/src/lib/widgets/DynamicWidget/prompts/PendingSignModal/DefaultPendingSignModalContent/DefaultPendingSignModalContent.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/prompts/PendingSignModal/DefaultPendingSignModalContent/DefaultPendingSignModalContent.js +1 -1
- package/src/lib/widgets/DynamicWidget/prompts/PrimaryNotConnectedModal/PrimaryNotConnectedModal.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/prompts/PrimaryNotConnectedModal/PrimaryNotConnectedModal.js +1 -1
- package/src/lib/widgets/DynamicWidget/prompts/QrCodeModalView/QrCodeModalView.cjs +6 -5
- package/src/lib/widgets/DynamicWidget/prompts/QrCodeModalView/QrCodeModalView.js +6 -5
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SocialSignInProviderEnum } from '@dynamic-labs/sdk-api';
|
|
2
|
+
|
|
3
|
+
const getSocialSignInProviderFromString = (provider) => {
|
|
4
|
+
if (!provider)
|
|
5
|
+
return;
|
|
6
|
+
const values = Object.values(SocialSignInProviderEnum);
|
|
7
|
+
for (const value of values) {
|
|
8
|
+
if (value === provider) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return undefined;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { getSocialSignInProviderFromString };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getSocialSignInProviderFromString } from './getSocialSignInProviderFromString';
|
|
@@ -29,3 +29,8 @@ export * from './digestSHA256';
|
|
|
29
29
|
export * from './encodeBase64URL';
|
|
30
30
|
export * from './getRedirectURIOrigin';
|
|
31
31
|
export * from './sendTransactionWithAutoNonce';
|
|
32
|
+
export * from './getProviderEnumForSocialSignInProvider';
|
|
33
|
+
export * from './getEnabledSocialSignInProvidersAsProviderEnum';
|
|
34
|
+
export * from './getActiveOauthCredential';
|
|
35
|
+
export * from './getSocialSignInProviderForProviderEnum';
|
|
36
|
+
export * from './getSocialSignInProviderFromString';
|
|
@@ -39,7 +39,8 @@ const useAuthLayoutChecks = (walletConnector) => {
|
|
|
39
39
|
view !== 'email-wallet-otp-verification-view' &&
|
|
40
40
|
view !== 'bridge-welcome' &&
|
|
41
41
|
view !== 'bridge-summary' &&
|
|
42
|
-
view !== 'bridge-next-wallet-connection'
|
|
42
|
+
view !== 'bridge-next-wallet-connection' &&
|
|
43
|
+
view !== 'social-redirect-view';
|
|
43
44
|
const showConnectedWalletProgress = isBridgeFlow &&
|
|
44
45
|
(view === 'wallet-list' ||
|
|
45
46
|
view === 'qr-code' ||
|
|
@@ -35,7 +35,8 @@ const useAuthLayoutChecks = (walletConnector) => {
|
|
|
35
35
|
view !== 'email-wallet-otp-verification-view' &&
|
|
36
36
|
view !== 'bridge-welcome' &&
|
|
37
37
|
view !== 'bridge-summary' &&
|
|
38
|
-
view !== 'bridge-next-wallet-connection'
|
|
38
|
+
view !== 'bridge-next-wallet-connection' &&
|
|
39
|
+
view !== 'social-redirect-view';
|
|
39
40
|
const showConnectedWalletProgress = isBridgeFlow &&
|
|
40
41
|
(view === 'wallet-list' ||
|
|
41
42
|
view === 'qr-code' ||
|
|
@@ -37,7 +37,7 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
const nextConnectedWallets = (yield Promise.all(connectedWalletsInfo.map((storedConnectedWalletInfo) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
const walletConnector = walletConnectorCore.
|
|
40
|
+
const walletConnector = walletConnectorCore.getWalletConnectorByKey(walletConnectors, storedConnectedWalletInfo.walletConnectorKey);
|
|
41
41
|
if (!walletConnector) {
|
|
42
42
|
walletConnectorCore.logger.error('Could not find walletConnector: ' +
|
|
43
43
|
storedConnectedWalletInfo.walletConnectorKey);
|
|
@@ -149,7 +149,7 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
149
149
|
setPrimaryWalletId(walletId);
|
|
150
150
|
}
|
|
151
151
|
const walletChain = walletConnector.connectedChain;
|
|
152
|
-
const isWalletStored = connectedWalletsInfo.some(({ walletConnectorKey: storedWalletConnectorKey }) => storedWalletConnectorKey === walletConnector.
|
|
152
|
+
const isWalletStored = connectedWalletsInfo.some(({ walletConnectorKey: storedWalletConnectorKey }) => storedWalletConnectorKey === walletConnector.key);
|
|
153
153
|
if (isWalletStored) {
|
|
154
154
|
yield updateConnectedWalletsList();
|
|
155
155
|
}
|
|
@@ -158,7 +158,7 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
158
158
|
provider: getWalletProvider.getWalletProvider(walletConnector),
|
|
159
159
|
walletAddress: publicWalletAddress,
|
|
160
160
|
walletChain,
|
|
161
|
-
walletConnectorKey: walletConnector.
|
|
161
|
+
walletConnectorKey: walletConnector.key,
|
|
162
162
|
walletId,
|
|
163
163
|
});
|
|
164
164
|
if (!shouldSkipCreatingVisit) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
2
2
|
import { useState, useCallback, useEffect } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { getWalletConnectorByKey, logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
4
|
import '@dynamic-labs/sdk-api';
|
|
5
5
|
import '../../../shared/logger.js';
|
|
6
6
|
import '@dynamic-labs/iconic';
|
|
@@ -33,7 +33,7 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
const nextConnectedWallets = (yield Promise.all(connectedWalletsInfo.map((storedConnectedWalletInfo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
const walletConnector =
|
|
36
|
+
const walletConnector = getWalletConnectorByKey(walletConnectors, storedConnectedWalletInfo.walletConnectorKey);
|
|
37
37
|
if (!walletConnector) {
|
|
38
38
|
logger.error('Could not find walletConnector: ' +
|
|
39
39
|
storedConnectedWalletInfo.walletConnectorKey);
|
|
@@ -145,7 +145,7 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
145
145
|
setPrimaryWalletId(walletId);
|
|
146
146
|
}
|
|
147
147
|
const walletChain = walletConnector.connectedChain;
|
|
148
|
-
const isWalletStored = connectedWalletsInfo.some(({ walletConnectorKey: storedWalletConnectorKey }) => storedWalletConnectorKey === walletConnector.
|
|
148
|
+
const isWalletStored = connectedWalletsInfo.some(({ walletConnectorKey: storedWalletConnectorKey }) => storedWalletConnectorKey === walletConnector.key);
|
|
149
149
|
if (isWalletStored) {
|
|
150
150
|
yield updateConnectedWalletsList();
|
|
151
151
|
}
|
|
@@ -154,7 +154,7 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
154
154
|
provider: getWalletProvider(walletConnector),
|
|
155
155
|
walletAddress: publicWalletAddress,
|
|
156
156
|
walletChain,
|
|
157
|
-
walletConnectorKey: walletConnector.
|
|
157
|
+
walletConnectorKey: walletConnector.key,
|
|
158
158
|
walletId,
|
|
159
159
|
});
|
|
160
160
|
if (!shouldSkipCreatingVisit) {
|
|
@@ -44,7 +44,16 @@ const useFetchProjectSettings = ({ authToken, environmentId, maxRetries = 2, dyn
|
|
|
44
44
|
environmentId &&
|
|
45
45
|
retries < maxRetries) {
|
|
46
46
|
setLoading(true);
|
|
47
|
-
|
|
47
|
+
// we ReactNode components are not being serialized properly
|
|
48
|
+
// remove them for now and deal with them later
|
|
49
|
+
// context: https://linear.app/dynamic-labs/issue/GVTY-328/[starknet]-sdk-api-is-not-serializing-react-components
|
|
50
|
+
// future work: https://linear.app/dynamic-labs/issue/GVTY-330/bug-figure-out-why-react-components-are-not
|
|
51
|
+
const updatedDynamicProps = {
|
|
52
|
+
settings: Object.assign(Object.assign({}, dynamicContextProps.settings), { customPrivacyPolicy: Boolean(dynamicContextProps.settings.customPrivacyPolicy), customTermsOfServices: Boolean(dynamicContextProps.settings.customTermsOfServices), policiesConsentInnerComponent: Boolean(dynamicContextProps.settings.policiesConsentInnerComponent) }),
|
|
53
|
+
};
|
|
54
|
+
api.sendDynamicProps(environmentId, {
|
|
55
|
+
dynamicContextProps: updatedDynamicProps,
|
|
56
|
+
});
|
|
48
57
|
api.fetchProjectSettings(environmentId)
|
|
49
58
|
.then((response) => {
|
|
50
59
|
if (!response)
|
|
@@ -40,7 +40,16 @@ const useFetchProjectSettings = ({ authToken, environmentId, maxRetries = 2, dyn
|
|
|
40
40
|
environmentId &&
|
|
41
41
|
retries < maxRetries) {
|
|
42
42
|
setLoading(true);
|
|
43
|
-
|
|
43
|
+
// we ReactNode components are not being serialized properly
|
|
44
|
+
// remove them for now and deal with them later
|
|
45
|
+
// context: https://linear.app/dynamic-labs/issue/GVTY-328/[starknet]-sdk-api-is-not-serializing-react-components
|
|
46
|
+
// future work: https://linear.app/dynamic-labs/issue/GVTY-330/bug-figure-out-why-react-components-are-not
|
|
47
|
+
const updatedDynamicProps = {
|
|
48
|
+
settings: Object.assign(Object.assign({}, dynamicContextProps.settings), { customPrivacyPolicy: Boolean(dynamicContextProps.settings.customPrivacyPolicy), customTermsOfServices: Boolean(dynamicContextProps.settings.customTermsOfServices), policiesConsentInnerComponent: Boolean(dynamicContextProps.settings.policiesConsentInnerComponent) }),
|
|
49
|
+
};
|
|
50
|
+
sendDynamicProps(environmentId, {
|
|
51
|
+
dynamicContextProps: updatedDynamicProps,
|
|
52
|
+
});
|
|
44
53
|
fetchProjectSettings(environmentId)
|
|
45
54
|
.then((response) => {
|
|
46
55
|
if (!response)
|
|
@@ -9,7 +9,7 @@ var useInternalDynamicContext = require('../../../context/DynamicContext/useInte
|
|
|
9
9
|
var api = require('../../../data/api.cjs');
|
|
10
10
|
var useUpdateUserProfileByJWTCallback = require('../useUpdateUserProfileByJWTCallback/useUpdateUserProfileByJWTCallback.cjs');
|
|
11
11
|
require('@dynamic-labs/sdk-api');
|
|
12
|
-
|
|
12
|
+
require('../../../shared/logger.cjs');
|
|
13
13
|
require('@dynamic-labs/iconic');
|
|
14
14
|
require('@dynamic-labs/wallet-connector-core');
|
|
15
15
|
require('react/jsx-runtime');
|
|
@@ -24,35 +24,19 @@ require('@dynamic-labs/multi-wallet');
|
|
|
24
24
|
var getAuthToken = require('../../functions/getAuthToken/getAuthToken.cjs');
|
|
25
25
|
var index = require('../../functions/getEnabledOAuthProviders/index.cjs');
|
|
26
26
|
var isSocialKycEnabled = require('../../functions/isSocialKycEnabled/isSocialKycEnabled.cjs');
|
|
27
|
-
var
|
|
28
|
-
var stringifyURIQuery = require('../../functions/stringifyURIQuery/stringifyURIQuery.cjs');
|
|
29
|
-
var digestSHA256 = require('../../functions/digestSHA256/digestSHA256.cjs');
|
|
30
|
-
var encodeBase64URL = require('../../functions/encodeBase64URL/encodeBase64URL.cjs');
|
|
31
|
-
var getRedirectURIOrigin = require('../../functions/getRedirectURIOrigin/getRedirectURIOrigin.cjs');
|
|
27
|
+
var useSocialAuth = require('../useSocialAuth/useSocialAuth.cjs');
|
|
32
28
|
|
|
33
|
-
|
|
34
|
-
'discord',
|
|
35
|
-
'facebook',
|
|
36
|
-
'github',
|
|
37
|
-
'google',
|
|
38
|
-
'instagram',
|
|
39
|
-
'twitch',
|
|
40
|
-
'twitter',
|
|
41
|
-
];
|
|
42
|
-
// pkce params are only required for twitter and break if added for other providers, like google
|
|
43
|
-
// so we should only add provider that support pkce to this list
|
|
44
|
-
const providersRequiringPkce = ['twitter', 'github'];
|
|
45
|
-
const providersWithoutWindowOpenerRefence = ['twitter'];
|
|
29
|
+
// Hook exposed to customers and used internally to handle social account linking
|
|
46
30
|
const useSocialAccounts = ({ sessionTimeout } = {
|
|
47
31
|
sessionTimeout: 10000,
|
|
48
32
|
}) => {
|
|
49
33
|
var _a;
|
|
50
34
|
const { environmentId, user, projectSettings, onboardingOnlyJwt } = useInternalDynamicContext.useInternalDynamicContext();
|
|
51
35
|
const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback.useUpdateUserProfileByJWTCallback();
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
36
|
+
const { handleError, setError, setIsProcessing, checkValidProvider, error, isProcessing, connectSocialAccount, } = useSocialAuth.useSocialAuth({
|
|
37
|
+
authMode: 'link',
|
|
38
|
+
sessionTimeout,
|
|
39
|
+
});
|
|
56
40
|
const userJwt = (_a = getAuthToken.getAuthToken()) !== null && _a !== void 0 ? _a : onboardingOnlyJwt;
|
|
57
41
|
const oauthProviders = index.getEnabledOAuthProviders(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
|
|
58
42
|
const verifiedOAuthCredentialsMap = React.useMemo(() => {
|
|
@@ -66,47 +50,11 @@ const useSocialAccounts = ({ sessionTimeout } = {
|
|
|
66
50
|
];
|
|
67
51
|
})));
|
|
68
52
|
}, [user === null || user === void 0 ? void 0 : user.verifiedCredentials]);
|
|
69
|
-
const handleError = (code, message) => {
|
|
70
|
-
logger.logger.error(message);
|
|
71
|
-
setIsProcessing(false);
|
|
72
|
-
setError({ code, message });
|
|
73
|
-
};
|
|
74
|
-
const addOAuthIFrame = (url) => {
|
|
75
|
-
const container = document.getElementById('oauth-iframe-container');
|
|
76
|
-
let oauthIFrame = document.getElementById('oauth-iframe');
|
|
77
|
-
if (!container || oauthIFrame) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
oauthIFrame = document.createElement('iframe');
|
|
81
|
-
oauthIFrame.setAttribute('id', 'oauth-iframe');
|
|
82
|
-
oauthIFrame.setAttribute('src', url);
|
|
83
|
-
container.appendChild(oauthIFrame);
|
|
84
|
-
};
|
|
85
|
-
const removeOAuthIFrame = () => {
|
|
86
|
-
const oauthIFrame = document.getElementById('oauth-iframe');
|
|
87
|
-
if (oauthIFrame) {
|
|
88
|
-
oauthIFrame.remove();
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
const checkValidProvider = (provider) => {
|
|
92
|
-
if (!provider) {
|
|
93
|
-
handleError(types.SocialOAuthErrorCode.NO_PROVIDER, 'Provider is required');
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
if (!socialProviders.includes(provider)) {
|
|
97
|
-
handleError(types.SocialOAuthErrorCode.INVALID_PROVIDER, `Invalid social provider. Valid providers are: ${socialProviders.join(', ')}`);
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
return true;
|
|
101
|
-
};
|
|
102
53
|
const checkValidOAuthLinking = (provider) => {
|
|
103
54
|
if (!isSocialKycEnabled.isSocialKycEnabled(projectSettings)) {
|
|
104
55
|
handleError(types.SocialOAuthErrorCode.SOCIAL_LINKING_NOT_ENABLED, 'Social linking is not enabled on the dashboard');
|
|
105
56
|
return false;
|
|
106
57
|
}
|
|
107
|
-
if (!checkValidProvider(provider)) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
58
|
const verifiedCredential = verifiedOAuthCredentialsMap[provider];
|
|
111
59
|
if (verifiedCredential) {
|
|
112
60
|
handleError(types.SocialOAuthErrorCode.ACCOUNT_ALREADY_LINKED, `Account already linked for provider: ${provider}`);
|
|
@@ -120,112 +68,10 @@ const useSocialAccounts = ({ sessionTimeout } = {
|
|
|
120
68
|
return true;
|
|
121
69
|
};
|
|
122
70
|
const linkSocialAccount = (provider) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
123
|
-
|
|
124
|
-
clearInterval(authWindowInterval.current);
|
|
125
|
-
setError(undefined);
|
|
126
|
-
setIsProcessing(true);
|
|
127
|
-
// invalid linking request
|
|
128
|
-
if (!checkValidOAuthLinking(provider)) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
const state = randomString.randomString(8);
|
|
132
|
-
const verifier = randomString.randomString(43);
|
|
133
|
-
const clearListeners = () => {
|
|
134
|
-
removeOAuthIFrame();
|
|
135
|
-
window.removeEventListener('message', handleAuthWindowMessage);
|
|
136
|
-
providersWaitingOauthMessages.current = Object.assign(Object.assign({}, providersWaitingOauthMessages.current), { [provider]: false });
|
|
137
|
-
};
|
|
138
|
-
const handleAuthWindowMessage = (event) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
-
var _c;
|
|
140
|
-
const message = event.data;
|
|
141
|
-
const isAuthorizationMessage = (message === null || message === void 0 ? void 0 : message.type) === 'authorization_response';
|
|
142
|
-
if (isAuthorizationMessage) {
|
|
143
|
-
logger.logger.debug('Message received', { data: message });
|
|
144
|
-
}
|
|
145
|
-
const isValidMessage = isAuthorizationMessage && (message === null || message === void 0 ? void 0 : message.provider) === provider;
|
|
146
|
-
// don't process imvalid messages for provider
|
|
147
|
-
if (!isValidMessage) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
setIsProcessing(true);
|
|
151
|
-
if (!((_c = providersWaitingOauthMessages.current) === null || _c === void 0 ? void 0 : _c[provider])) {
|
|
152
|
-
handleError(types.SocialOAuthErrorCode.SESSION_TIMEOUT, `Linking ${provider} account session timeout.`);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
clearListeners();
|
|
156
|
-
const { code, error } = message;
|
|
157
|
-
if (error && error !== 'undefined') {
|
|
158
|
-
handleError(types.SocialOAuthErrorCode.OAUTH_ERROR, `Failed to link ${provider} social account: ${error}`);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
if (!code) {
|
|
162
|
-
handleError(types.SocialOAuthErrorCode.NO_AUTH_CODE, `Failed to link ${provider} social account: no authorization code`);
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
const jwt = yield api.verifyOAuth(environmentId, provider, {
|
|
166
|
-
code,
|
|
167
|
-
codeVerifier: verifier,
|
|
168
|
-
state,
|
|
169
|
-
}, String(userJwt));
|
|
170
|
-
if (!jwt) {
|
|
171
|
-
handleError(types.SocialOAuthErrorCode.VERIFICATION_ERROR, `Failed to link social account: ${provider}`);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
yield updateUserProfileByJWT(jwt);
|
|
175
|
-
setIsProcessing(false);
|
|
176
|
-
});
|
|
177
|
-
const loginUrl = yield api.getOauthLoginUrl(environmentId, provider, String(userJwt));
|
|
178
|
-
if (!loginUrl) {
|
|
179
|
-
handleError(types.SocialOAuthErrorCode.NO_OAUTH_URL, `Failed to get login url to link social account: ${provider}`);
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
// we need to use an iframe to be the intermediary in communications between the popup and the sdk
|
|
183
|
-
// because of twitter limitations with accessing the window.opener and BroadcastChannel not working between
|
|
184
|
-
// different origins (our api redirect page and the app where the sdk is running)
|
|
185
|
-
const oauthIFrameUrl = `${getRedirectURIOrigin.getRedirectURIOrigin(loginUrl)}/sdkoauth`;
|
|
186
|
-
addOAuthIFrame(oauthIFrameUrl);
|
|
187
|
-
let oauthLoginUrl = loginUrl;
|
|
188
|
-
if (providersRequiringPkce.includes(provider)) {
|
|
189
|
-
const digest = yield digestSHA256.digestSHA256(verifier);
|
|
190
|
-
const pkceParams = stringifyURIQuery.stringifyURIQuery({
|
|
191
|
-
code_challenge: encodeBase64URL.encodeBase64URL(digest),
|
|
192
|
-
code_challenge_method: 'S256',
|
|
193
|
-
state: state,
|
|
194
|
-
});
|
|
195
|
-
oauthLoginUrl = `${loginUrl}&${pkceParams}`;
|
|
196
|
-
}
|
|
197
|
-
if (!((_b = providersWaitingOauthMessages.current) === null || _b === void 0 ? void 0 : _b[provider])) {
|
|
198
|
-
window.addEventListener('message', handleAuthWindowMessage);
|
|
199
|
-
providersWaitingOauthMessages.current = Object.assign(Object.assign({}, providersWaitingOauthMessages.current), { [provider]: true });
|
|
200
|
-
}
|
|
201
|
-
const authWindow = window.open(oauthLoginUrl, '_blank', 'width=500,height=600');
|
|
202
|
-
if (!providersWithoutWindowOpenerRefence.includes(provider)) {
|
|
203
|
-
// For provider that support window.opener, we need to clear all states/listeners when the window is closed
|
|
204
|
-
authWindowInterval.current = setInterval(() => {
|
|
205
|
-
if (!(authWindow === null || authWindow === void 0 ? void 0 : authWindow.closed)) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
clearInterval(authWindowInterval.current);
|
|
209
|
-
setIsProcessing(false);
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
// For provider that don't support window.opener, we need to use a timeout to try to detect when the
|
|
214
|
-
// window is closed
|
|
215
|
-
authWindowInterval.current = setInterval(() => {
|
|
216
|
-
var _a;
|
|
217
|
-
// user didn't complete oauth
|
|
218
|
-
if ((_a = providersWaitingOauthMessages.current) === null || _a === void 0 ? void 0 : _a[provider]) {
|
|
219
|
-
clearListeners();
|
|
220
|
-
handleError(types.SocialOAuthErrorCode.OAUTH_WINDOW_TIMEOUT, `Linking ${provider} account window timeout.`);
|
|
221
|
-
}
|
|
222
|
-
setIsProcessing(false);
|
|
223
|
-
clearInterval(authWindowInterval.current);
|
|
224
|
-
}, sessionTimeout);
|
|
225
|
-
}
|
|
71
|
+
connectSocialAccount(provider, checkValidOAuthLinking);
|
|
226
72
|
});
|
|
227
73
|
const unlinkSocialAccount = (provider) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
228
|
-
var
|
|
74
|
+
var _b;
|
|
229
75
|
setError(undefined);
|
|
230
76
|
setIsProcessing(true);
|
|
231
77
|
if (!checkValidProvider(provider)) {
|
|
@@ -239,7 +85,7 @@ const useSocialAccounts = ({ sessionTimeout } = {
|
|
|
239
85
|
try {
|
|
240
86
|
const jwt = yield api.unlinkOAuth({
|
|
241
87
|
environmentId,
|
|
242
|
-
verifiedCrentialId: (
|
|
88
|
+
verifiedCrentialId: (_b = verifiedCredential.id) !== null && _b !== void 0 ? _b : '',
|
|
243
89
|
}, String(userJwt));
|
|
244
90
|
if (!jwt) {
|
|
245
91
|
handleError(types.SocialOAuthErrorCode.UNLINK_ERROR, `Failed to unlink social account: ${provider} | ${verifiedCredential.id}`);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ProviderEnum } from '@dynamic-labs/sdk-api';
|
|
2
|
-
import { SocialAccountInformation
|
|
2
|
+
import { SocialAccountInformation } from '@dynamic-labs/types';
|
|
3
3
|
type UseSocialAccountsProps = {
|
|
4
4
|
sessionTimeout: number;
|
|
5
5
|
};
|
|
6
6
|
export declare const useSocialAccounts: ({ sessionTimeout }?: UseSocialAccountsProps) => {
|
|
7
|
-
readonly error: SocialOAuthError | undefined;
|
|
7
|
+
readonly error: import("@dynamic-labs/types").SocialOAuthError | undefined;
|
|
8
8
|
readonly getLinkedAccountInformation: (provider: ProviderEnum) => SocialAccountInformation | undefined;
|
|
9
9
|
readonly isLinked: (provider: ProviderEnum) => boolean;
|
|
10
10
|
readonly isProcessing: boolean;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
2
|
-
import {
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
3
|
import { SocialOAuthErrorCode } from '@dynamic-labs/types';
|
|
4
4
|
import { useInternalDynamicContext } from '../../../context/DynamicContext/useInternalDynamicContext.js';
|
|
5
|
-
import {
|
|
5
|
+
import { unlinkOAuth } from '../../../data/api.js';
|
|
6
6
|
import { useUpdateUserProfileByJWTCallback } from '../useUpdateUserProfileByJWTCallback/useUpdateUserProfileByJWTCallback.js';
|
|
7
7
|
import '@dynamic-labs/sdk-api';
|
|
8
|
-
import
|
|
8
|
+
import '../../../shared/logger.js';
|
|
9
9
|
import '@dynamic-labs/iconic';
|
|
10
10
|
import '@dynamic-labs/wallet-connector-core';
|
|
11
11
|
import 'react/jsx-runtime';
|
|
@@ -20,35 +20,19 @@ import '@dynamic-labs/multi-wallet';
|
|
|
20
20
|
import { getAuthToken } from '../../functions/getAuthToken/getAuthToken.js';
|
|
21
21
|
import { getEnabledOAuthProviders } from '../../functions/getEnabledOAuthProviders/index.js';
|
|
22
22
|
import { isSocialKycEnabled } from '../../functions/isSocialKycEnabled/isSocialKycEnabled.js';
|
|
23
|
-
import {
|
|
24
|
-
import { stringifyURIQuery } from '../../functions/stringifyURIQuery/stringifyURIQuery.js';
|
|
25
|
-
import { digestSHA256 } from '../../functions/digestSHA256/digestSHA256.js';
|
|
26
|
-
import { encodeBase64URL } from '../../functions/encodeBase64URL/encodeBase64URL.js';
|
|
27
|
-
import { getRedirectURIOrigin } from '../../functions/getRedirectURIOrigin/getRedirectURIOrigin.js';
|
|
23
|
+
import { useSocialAuth } from '../useSocialAuth/useSocialAuth.js';
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
'discord',
|
|
31
|
-
'facebook',
|
|
32
|
-
'github',
|
|
33
|
-
'google',
|
|
34
|
-
'instagram',
|
|
35
|
-
'twitch',
|
|
36
|
-
'twitter',
|
|
37
|
-
];
|
|
38
|
-
// pkce params are only required for twitter and break if added for other providers, like google
|
|
39
|
-
// so we should only add provider that support pkce to this list
|
|
40
|
-
const providersRequiringPkce = ['twitter', 'github'];
|
|
41
|
-
const providersWithoutWindowOpenerRefence = ['twitter'];
|
|
25
|
+
// Hook exposed to customers and used internally to handle social account linking
|
|
42
26
|
const useSocialAccounts = ({ sessionTimeout } = {
|
|
43
27
|
sessionTimeout: 10000,
|
|
44
28
|
}) => {
|
|
45
29
|
var _a;
|
|
46
30
|
const { environmentId, user, projectSettings, onboardingOnlyJwt } = useInternalDynamicContext();
|
|
47
31
|
const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback();
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
32
|
+
const { handleError, setError, setIsProcessing, checkValidProvider, error, isProcessing, connectSocialAccount, } = useSocialAuth({
|
|
33
|
+
authMode: 'link',
|
|
34
|
+
sessionTimeout,
|
|
35
|
+
});
|
|
52
36
|
const userJwt = (_a = getAuthToken()) !== null && _a !== void 0 ? _a : onboardingOnlyJwt;
|
|
53
37
|
const oauthProviders = getEnabledOAuthProviders(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
|
|
54
38
|
const verifiedOAuthCredentialsMap = useMemo(() => {
|
|
@@ -62,47 +46,11 @@ const useSocialAccounts = ({ sessionTimeout } = {
|
|
|
62
46
|
];
|
|
63
47
|
})));
|
|
64
48
|
}, [user === null || user === void 0 ? void 0 : user.verifiedCredentials]);
|
|
65
|
-
const handleError = (code, message) => {
|
|
66
|
-
logger.error(message);
|
|
67
|
-
setIsProcessing(false);
|
|
68
|
-
setError({ code, message });
|
|
69
|
-
};
|
|
70
|
-
const addOAuthIFrame = (url) => {
|
|
71
|
-
const container = document.getElementById('oauth-iframe-container');
|
|
72
|
-
let oauthIFrame = document.getElementById('oauth-iframe');
|
|
73
|
-
if (!container || oauthIFrame) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
oauthIFrame = document.createElement('iframe');
|
|
77
|
-
oauthIFrame.setAttribute('id', 'oauth-iframe');
|
|
78
|
-
oauthIFrame.setAttribute('src', url);
|
|
79
|
-
container.appendChild(oauthIFrame);
|
|
80
|
-
};
|
|
81
|
-
const removeOAuthIFrame = () => {
|
|
82
|
-
const oauthIFrame = document.getElementById('oauth-iframe');
|
|
83
|
-
if (oauthIFrame) {
|
|
84
|
-
oauthIFrame.remove();
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
const checkValidProvider = (provider) => {
|
|
88
|
-
if (!provider) {
|
|
89
|
-
handleError(SocialOAuthErrorCode.NO_PROVIDER, 'Provider is required');
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
if (!socialProviders.includes(provider)) {
|
|
93
|
-
handleError(SocialOAuthErrorCode.INVALID_PROVIDER, `Invalid social provider. Valid providers are: ${socialProviders.join(', ')}`);
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
return true;
|
|
97
|
-
};
|
|
98
49
|
const checkValidOAuthLinking = (provider) => {
|
|
99
50
|
if (!isSocialKycEnabled(projectSettings)) {
|
|
100
51
|
handleError(SocialOAuthErrorCode.SOCIAL_LINKING_NOT_ENABLED, 'Social linking is not enabled on the dashboard');
|
|
101
52
|
return false;
|
|
102
53
|
}
|
|
103
|
-
if (!checkValidProvider(provider)) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
54
|
const verifiedCredential = verifiedOAuthCredentialsMap[provider];
|
|
107
55
|
if (verifiedCredential) {
|
|
108
56
|
handleError(SocialOAuthErrorCode.ACCOUNT_ALREADY_LINKED, `Account already linked for provider: ${provider}`);
|
|
@@ -116,112 +64,10 @@ const useSocialAccounts = ({ sessionTimeout } = {
|
|
|
116
64
|
return true;
|
|
117
65
|
};
|
|
118
66
|
const linkSocialAccount = (provider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
119
|
-
|
|
120
|
-
clearInterval(authWindowInterval.current);
|
|
121
|
-
setError(undefined);
|
|
122
|
-
setIsProcessing(true);
|
|
123
|
-
// invalid linking request
|
|
124
|
-
if (!checkValidOAuthLinking(provider)) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const state = randomString(8);
|
|
128
|
-
const verifier = randomString(43);
|
|
129
|
-
const clearListeners = () => {
|
|
130
|
-
removeOAuthIFrame();
|
|
131
|
-
window.removeEventListener('message', handleAuthWindowMessage);
|
|
132
|
-
providersWaitingOauthMessages.current = Object.assign(Object.assign({}, providersWaitingOauthMessages.current), { [provider]: false });
|
|
133
|
-
};
|
|
134
|
-
const handleAuthWindowMessage = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
-
var _c;
|
|
136
|
-
const message = event.data;
|
|
137
|
-
const isAuthorizationMessage = (message === null || message === void 0 ? void 0 : message.type) === 'authorization_response';
|
|
138
|
-
if (isAuthorizationMessage) {
|
|
139
|
-
logger.debug('Message received', { data: message });
|
|
140
|
-
}
|
|
141
|
-
const isValidMessage = isAuthorizationMessage && (message === null || message === void 0 ? void 0 : message.provider) === provider;
|
|
142
|
-
// don't process imvalid messages for provider
|
|
143
|
-
if (!isValidMessage) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
setIsProcessing(true);
|
|
147
|
-
if (!((_c = providersWaitingOauthMessages.current) === null || _c === void 0 ? void 0 : _c[provider])) {
|
|
148
|
-
handleError(SocialOAuthErrorCode.SESSION_TIMEOUT, `Linking ${provider} account session timeout.`);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
clearListeners();
|
|
152
|
-
const { code, error } = message;
|
|
153
|
-
if (error && error !== 'undefined') {
|
|
154
|
-
handleError(SocialOAuthErrorCode.OAUTH_ERROR, `Failed to link ${provider} social account: ${error}`);
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
if (!code) {
|
|
158
|
-
handleError(SocialOAuthErrorCode.NO_AUTH_CODE, `Failed to link ${provider} social account: no authorization code`);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
const jwt = yield verifyOAuth(environmentId, provider, {
|
|
162
|
-
code,
|
|
163
|
-
codeVerifier: verifier,
|
|
164
|
-
state,
|
|
165
|
-
}, String(userJwt));
|
|
166
|
-
if (!jwt) {
|
|
167
|
-
handleError(SocialOAuthErrorCode.VERIFICATION_ERROR, `Failed to link social account: ${provider}`);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
yield updateUserProfileByJWT(jwt);
|
|
171
|
-
setIsProcessing(false);
|
|
172
|
-
});
|
|
173
|
-
const loginUrl = yield getOauthLoginUrl(environmentId, provider, String(userJwt));
|
|
174
|
-
if (!loginUrl) {
|
|
175
|
-
handleError(SocialOAuthErrorCode.NO_OAUTH_URL, `Failed to get login url to link social account: ${provider}`);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
// we need to use an iframe to be the intermediary in communications between the popup and the sdk
|
|
179
|
-
// because of twitter limitations with accessing the window.opener and BroadcastChannel not working between
|
|
180
|
-
// different origins (our api redirect page and the app where the sdk is running)
|
|
181
|
-
const oauthIFrameUrl = `${getRedirectURIOrigin(loginUrl)}/sdkoauth`;
|
|
182
|
-
addOAuthIFrame(oauthIFrameUrl);
|
|
183
|
-
let oauthLoginUrl = loginUrl;
|
|
184
|
-
if (providersRequiringPkce.includes(provider)) {
|
|
185
|
-
const digest = yield digestSHA256(verifier);
|
|
186
|
-
const pkceParams = stringifyURIQuery({
|
|
187
|
-
code_challenge: encodeBase64URL(digest),
|
|
188
|
-
code_challenge_method: 'S256',
|
|
189
|
-
state: state,
|
|
190
|
-
});
|
|
191
|
-
oauthLoginUrl = `${loginUrl}&${pkceParams}`;
|
|
192
|
-
}
|
|
193
|
-
if (!((_b = providersWaitingOauthMessages.current) === null || _b === void 0 ? void 0 : _b[provider])) {
|
|
194
|
-
window.addEventListener('message', handleAuthWindowMessage);
|
|
195
|
-
providersWaitingOauthMessages.current = Object.assign(Object.assign({}, providersWaitingOauthMessages.current), { [provider]: true });
|
|
196
|
-
}
|
|
197
|
-
const authWindow = window.open(oauthLoginUrl, '_blank', 'width=500,height=600');
|
|
198
|
-
if (!providersWithoutWindowOpenerRefence.includes(provider)) {
|
|
199
|
-
// For provider that support window.opener, we need to clear all states/listeners when the window is closed
|
|
200
|
-
authWindowInterval.current = setInterval(() => {
|
|
201
|
-
if (!(authWindow === null || authWindow === void 0 ? void 0 : authWindow.closed)) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
clearInterval(authWindowInterval.current);
|
|
205
|
-
setIsProcessing(false);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
// For provider that don't support window.opener, we need to use a timeout to try to detect when the
|
|
210
|
-
// window is closed
|
|
211
|
-
authWindowInterval.current = setInterval(() => {
|
|
212
|
-
var _a;
|
|
213
|
-
// user didn't complete oauth
|
|
214
|
-
if ((_a = providersWaitingOauthMessages.current) === null || _a === void 0 ? void 0 : _a[provider]) {
|
|
215
|
-
clearListeners();
|
|
216
|
-
handleError(SocialOAuthErrorCode.OAUTH_WINDOW_TIMEOUT, `Linking ${provider} account window timeout.`);
|
|
217
|
-
}
|
|
218
|
-
setIsProcessing(false);
|
|
219
|
-
clearInterval(authWindowInterval.current);
|
|
220
|
-
}, sessionTimeout);
|
|
221
|
-
}
|
|
67
|
+
connectSocialAccount(provider, checkValidOAuthLinking);
|
|
222
68
|
});
|
|
223
69
|
const unlinkSocialAccount = (provider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
224
|
-
var
|
|
70
|
+
var _b;
|
|
225
71
|
setError(undefined);
|
|
226
72
|
setIsProcessing(true);
|
|
227
73
|
if (!checkValidProvider(provider)) {
|
|
@@ -235,7 +81,7 @@ const useSocialAccounts = ({ sessionTimeout } = {
|
|
|
235
81
|
try {
|
|
236
82
|
const jwt = yield unlinkOAuth({
|
|
237
83
|
environmentId,
|
|
238
|
-
verifiedCrentialId: (
|
|
84
|
+
verifiedCrentialId: (_b = verifiedCredential.id) !== null && _b !== void 0 ? _b : '',
|
|
239
85
|
}, String(userJwt));
|
|
240
86
|
if (!jwt) {
|
|
241
87
|
handleError(SocialOAuthErrorCode.UNLINK_ERROR, `Failed to unlink social account: ${provider} | ${verifiedCredential.id}`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSocialAuth } from './useSocialAuth';
|