@turnkey/react-wallet-kit 1.0.0-beta.6 → 1.1.0
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/README.MD +5 -2
- package/dist/_virtual/_rollupPluginBabelHelpers.mjs +95 -256
- package/dist/_virtual/_rollupPluginBabelHelpers.mjs.map +1 -1
- package/dist/components/auth/Action.js.map +1 -1
- package/dist/components/auth/Action.mjs +18 -18
- package/dist/components/auth/Action.mjs.map +1 -1
- package/dist/components/auth/Email.d.ts.map +1 -1
- package/dist/components/auth/Email.js +3 -0
- package/dist/components/auth/Email.js.map +1 -1
- package/dist/components/auth/Email.mjs +16 -14
- package/dist/components/auth/Email.mjs.map +1 -1
- package/dist/components/auth/OAuth.d.ts.map +1 -1
- package/dist/components/auth/OAuth.js +1 -0
- package/dist/components/auth/OAuth.js.map +1 -1
- package/dist/components/auth/OAuth.mjs +1 -0
- package/dist/components/auth/OAuth.mjs.map +1 -1
- package/dist/components/auth/OTP.d.ts +2 -2
- package/dist/components/auth/OTP.d.ts.map +1 -1
- package/dist/components/auth/OTP.js +1 -1
- package/dist/components/auth/OTP.js.map +1 -1
- package/dist/components/auth/OTP.mjs +46 -48
- package/dist/components/auth/OTP.mjs.map +1 -1
- package/dist/components/auth/OrSeparator.js.map +1 -1
- package/dist/components/auth/OrSeparator.mjs.map +1 -1
- package/dist/components/auth/Passkey.d.ts.map +1 -1
- package/dist/components/auth/Passkey.js +2 -0
- package/dist/components/auth/Passkey.js.map +1 -1
- package/dist/components/auth/Passkey.mjs +2 -0
- package/dist/components/auth/Passkey.mjs.map +1 -1
- package/dist/components/auth/Phone.js.map +1 -1
- package/dist/components/auth/Phone.mjs +13 -14
- package/dist/components/auth/Phone.mjs.map +1 -1
- package/dist/components/auth/Wallet.d.ts +2 -2
- package/dist/components/auth/Wallet.d.ts.map +1 -1
- package/dist/components/auth/Wallet.js +90 -49
- package/dist/components/auth/Wallet.js.map +1 -1
- package/dist/components/auth/Wallet.mjs +155 -116
- package/dist/components/auth/Wallet.mjs.map +1 -1
- package/dist/components/auth/index.d.ts +4 -1
- package/dist/components/auth/index.d.ts.map +1 -1
- package/dist/components/auth/index.js +44 -7
- package/dist/components/auth/index.js.map +1 -1
- package/dist/components/auth/index.mjs +160 -138
- package/dist/components/auth/index.mjs.map +1 -1
- package/dist/components/design/Buttons.d.ts +2 -0
- package/dist/components/design/Buttons.d.ts.map +1 -1
- package/dist/components/design/Buttons.js +8 -2
- package/dist/components/design/Buttons.js.map +1 -1
- package/dist/components/design/Buttons.mjs +9 -3
- package/dist/components/design/Buttons.mjs.map +1 -1
- package/dist/components/design/Failure.js.map +1 -1
- package/dist/components/design/Failure.mjs.map +1 -1
- package/dist/components/design/Inputs.js.map +1 -1
- package/dist/components/design/Inputs.mjs.map +1 -1
- package/dist/components/design/Lottie/Dynamic.mjs +8 -11
- package/dist/components/design/Lottie/Dynamic.mjs.map +1 -1
- package/dist/components/design/Lottie/Wrapper.js.map +1 -1
- package/dist/components/design/Lottie/Wrapper.mjs +9 -10
- package/dist/components/design/Lottie/Wrapper.mjs.map +1 -1
- package/dist/components/design/Spinners.js.map +1 -1
- package/dist/components/design/Spinners.mjs.map +1 -1
- package/dist/components/design/Success.js.map +1 -1
- package/dist/components/design/Success.mjs.map +1 -1
- package/dist/components/design/Svg.js.map +1 -1
- package/dist/components/design/Svg.mjs.map +1 -1
- package/dist/components/export/Export.d.ts +3 -0
- package/dist/components/export/Export.d.ts.map +1 -1
- package/dist/components/export/Export.js +13 -4
- package/dist/components/export/Export.js.map +1 -1
- package/dist/components/export/Export.mjs +36 -29
- package/dist/components/export/Export.mjs.map +1 -1
- package/dist/components/export/ExportWarning.d.ts +2 -0
- package/dist/components/export/ExportWarning.d.ts.map +1 -1
- package/dist/components/export/ExportWarning.js +18 -9
- package/dist/components/export/ExportWarning.js.map +1 -1
- package/dist/components/export/ExportWarning.mjs +65 -63
- package/dist/components/export/ExportWarning.mjs.map +1 -1
- package/dist/components/import/Import.d.ts +3 -0
- package/dist/components/import/Import.d.ts.map +1 -1
- package/dist/components/import/Import.js +32 -16
- package/dist/components/import/Import.js.map +1 -1
- package/dist/components/import/Import.mjs +127 -114
- package/dist/components/import/Import.mjs.map +1 -1
- package/dist/components/sign/Message.d.ts +1 -0
- package/dist/components/sign/Message.d.ts.map +1 -1
- package/dist/components/sign/Message.js +5 -0
- package/dist/components/sign/Message.js.map +1 -1
- package/dist/components/sign/Message.mjs +25 -22
- package/dist/components/sign/Message.mjs.map +1 -1
- package/dist/components/user/ConnectWallet.d.ts +2 -0
- package/dist/components/user/ConnectWallet.d.ts.map +1 -1
- package/dist/components/user/ConnectWallet.js +41 -29
- package/dist/components/user/ConnectWallet.js.map +1 -1
- package/dist/components/user/ConnectWallet.mjs +48 -32
- package/dist/components/user/ConnectWallet.mjs.map +1 -1
- package/dist/components/user/RemoveEmail.d.ts +1 -0
- package/dist/components/user/RemoveEmail.d.ts.map +1 -1
- package/dist/components/user/RemoveEmail.js +7 -3
- package/dist/components/user/RemoveEmail.js.map +1 -1
- package/dist/components/user/RemoveEmail.mjs +27 -25
- package/dist/components/user/RemoveEmail.mjs.map +1 -1
- package/dist/components/user/RemoveOAuthProvider.d.ts +1 -0
- package/dist/components/user/RemoveOAuthProvider.d.ts.map +1 -1
- package/dist/components/user/RemoveOAuthProvider.js +7 -3
- package/dist/components/user/RemoveOAuthProvider.js.map +1 -1
- package/dist/components/user/RemoveOAuthProvider.mjs +27 -25
- package/dist/components/user/RemoveOAuthProvider.mjs.map +1 -1
- package/dist/components/user/RemovePasskey.d.ts +1 -0
- package/dist/components/user/RemovePasskey.d.ts.map +1 -1
- package/dist/components/user/RemovePasskey.js +7 -2
- package/dist/components/user/RemovePasskey.js.map +1 -1
- package/dist/components/user/RemovePasskey.mjs +27 -24
- package/dist/components/user/RemovePasskey.mjs.map +1 -1
- package/dist/components/user/RemovePhoneNumber.d.ts +1 -0
- package/dist/components/user/RemovePhoneNumber.d.ts.map +1 -1
- package/dist/components/user/RemovePhoneNumber.js +7 -3
- package/dist/components/user/RemovePhoneNumber.js.map +1 -1
- package/dist/components/user/RemovePhoneNumber.mjs +27 -25
- package/dist/components/user/RemovePhoneNumber.mjs.map +1 -1
- package/dist/components/user/UpdateEmail.d.ts +4 -0
- package/dist/components/user/UpdateEmail.d.ts.map +1 -1
- package/dist/components/user/UpdateEmail.js +13 -3
- package/dist/components/user/UpdateEmail.js.map +1 -1
- package/dist/components/user/UpdateEmail.mjs +46 -39
- package/dist/components/user/UpdateEmail.mjs.map +1 -1
- package/dist/components/user/UpdatePhoneNumber.d.ts +4 -0
- package/dist/components/user/UpdatePhoneNumber.d.ts.map +1 -1
- package/dist/components/user/UpdatePhoneNumber.js +13 -3
- package/dist/components/user/UpdatePhoneNumber.js.map +1 -1
- package/dist/components/user/UpdatePhoneNumber.mjs +46 -39
- package/dist/components/user/UpdatePhoneNumber.mjs.map +1 -1
- package/dist/components/user/UpdateUserName.d.ts +2 -0
- package/dist/components/user/UpdateUserName.d.ts.map +1 -1
- package/dist/components/user/UpdateUserName.js +4 -3
- package/dist/components/user/UpdateUserName.js.map +1 -1
- package/dist/components/user/UpdateUserName.mjs +25 -25
- package/dist/components/user/UpdateUserName.mjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providers/TurnkeyProvider.js.map +1 -1
- package/dist/providers/TurnkeyProvider.mjs.map +1 -1
- package/dist/providers/client/Hook.js.map +1 -1
- package/dist/providers/client/Hook.mjs.map +1 -1
- package/dist/providers/client/Provider.d.ts.map +1 -1
- package/dist/providers/client/Provider.js +705 -343
- package/dist/providers/client/Provider.js.map +1 -1
- package/dist/providers/client/Provider.mjs +2676 -2211
- package/dist/providers/client/Provider.mjs.map +1 -1
- package/dist/providers/client/Types.d.ts +100 -171
- package/dist/providers/client/Types.d.ts.map +1 -1
- package/dist/providers/client/Types.js.map +1 -1
- package/dist/providers/client/Types.mjs.map +1 -1
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/modal/Hook.js.map +1 -1
- package/dist/providers/modal/Hook.mjs.map +1 -1
- package/dist/providers/modal/Provider.d.ts +3 -0
- package/dist/providers/modal/Provider.d.ts.map +1 -1
- package/dist/providers/modal/Provider.js +10 -1
- package/dist/providers/modal/Provider.js.map +1 -1
- package/dist/providers/modal/Provider.mjs +15 -1
- package/dist/providers/modal/Provider.mjs.map +1 -1
- package/dist/providers/modal/Root.d.ts.map +1 -1
- package/dist/providers/modal/Root.js +74 -2
- package/dist/providers/modal/Root.js.map +1 -1
- package/dist/providers/modal/Root.mjs +92 -15
- package/dist/providers/modal/Root.mjs.map +1 -1
- package/dist/providers/theme/Overrides.js.map +1 -1
- package/dist/providers/theme/Overrides.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/tests/timers-test.d.ts +2 -0
- package/dist/tests/timers-test.d.ts.map +1 -0
- package/dist/tests/utils-test.d.ts +2 -0
- package/dist/tests/utils-test.d.ts.map +1 -0
- package/dist/typedoc-entry/index.d.ts +4 -0
- package/dist/typedoc-entry/index.d.ts.map +1 -0
- package/dist/types/base.d.ts +11 -2
- package/dist/types/base.d.ts.map +1 -1
- package/dist/types/base.js.map +1 -1
- package/dist/types/base.mjs.map +1 -1
- package/dist/types/method-types.d.ts +210 -0
- package/dist/types/method-types.d.ts.map +1 -0
- package/dist/utils/timers.js.map +1 -1
- package/dist/utils/timers.mjs.map +1 -1
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +15 -5
- package/dist/utils/utils.js.map +1 -1
- package/dist/utils/utils.mjs +92 -86
- package/dist/utils/utils.mjs.map +1 -1
- package/package.json +6 -5
|
@@ -75,6 +75,7 @@ const ClientProvider = ({
|
|
|
75
75
|
const proxyAuthConfigRef = react.useRef(null);
|
|
76
76
|
const [allSessions, setAllSessions] = react.useState(undefined);
|
|
77
77
|
const {
|
|
78
|
+
isMobile,
|
|
78
79
|
pushPage,
|
|
79
80
|
closeModal
|
|
80
81
|
} = Hook.useModal();
|
|
@@ -166,6 +167,7 @@ const ClientProvider = ({
|
|
|
166
167
|
authCode: code,
|
|
167
168
|
redirectUri: redirectURI,
|
|
168
169
|
codeVerifier: verifier,
|
|
170
|
+
clientId,
|
|
169
171
|
nonce: nonce
|
|
170
172
|
});
|
|
171
173
|
sessionStorage.removeItem("discord_verifier");
|
|
@@ -220,6 +222,7 @@ const ClientProvider = ({
|
|
|
220
222
|
authCode: code,
|
|
221
223
|
redirectUri: redirectURI,
|
|
222
224
|
codeVerifier: verifier,
|
|
225
|
+
clientId,
|
|
223
226
|
nonce: nonce
|
|
224
227
|
});
|
|
225
228
|
sessionStorage.removeItem("twitter_verifier");
|
|
@@ -347,25 +350,55 @@ const ClientProvider = ({
|
|
|
347
350
|
appleOauthEnabled: config.auth?.methods?.appleOauthEnabled ?? proxyAuthConfig?.enabledProviders.includes("apple"),
|
|
348
351
|
facebookOauthEnabled: config.auth?.methods?.facebookOauthEnabled ?? proxyAuthConfig?.enabledProviders.includes("facebook")
|
|
349
352
|
};
|
|
353
|
+
const resolvedClientIds = {
|
|
354
|
+
googleClientId: config.auth?.oauthConfig?.googleClientId ?? proxyAuthConfig?.oauthClientIds?.google,
|
|
355
|
+
appleClientId: config.auth?.oauthConfig?.appleClientId ?? proxyAuthConfig?.oauthClientIds?.apple,
|
|
356
|
+
facebookClientId: config.auth?.oauthConfig?.facebookClientId ?? proxyAuthConfig?.oauthClientIds?.facebook,
|
|
357
|
+
xClientId: config.auth?.oauthConfig?.xClientId ?? proxyAuthConfig?.oauthClientIds?.x,
|
|
358
|
+
discordClientId: config.auth?.oauthConfig?.discordClientId ?? proxyAuthConfig?.oauthClientIds?.discord
|
|
359
|
+
};
|
|
360
|
+
const redirectUrl = config.auth?.oauthConfig?.oauthRedirectUri ?? proxyAuthConfig?.oauthRedirectUrl;
|
|
350
361
|
// Set a default ordering for the oAuth methods
|
|
351
362
|
const oauthOrder = config.auth?.oauthOrder ?? ["google", "apple", "x", "discord", "facebook"].filter(provider => resolvedMethods[`${provider}OauthEnabled`]);
|
|
352
363
|
// Set a default ordering for the overall auth methods
|
|
353
364
|
const methodOrder = config.auth?.methodOrder ?? [oauthOrder.length > 0 ? "socials" : null, resolvedMethods.emailOtpAuthEnabled ? "email" : null, resolvedMethods.smsOtpAuthEnabled ? "sms" : null, resolvedMethods.passkeyAuthEnabled ? "passkey" : null, resolvedMethods.walletAuthEnabled ? "wallet" : null].filter(Boolean);
|
|
365
|
+
// Warn if they are trying to set auth proxy only settings directly
|
|
366
|
+
if (config.auth?.sessionExpirationSeconds) {
|
|
367
|
+
console.warn("Turnkey SDK warning. You have set sessionExpirationSeconds directly in the TurnkeyProvider. This setting will be ignored because you are using an auth proxy. Please configure session expiration in the Turnkey dashboard.");
|
|
368
|
+
}
|
|
369
|
+
if (config.auth?.otpAlphanumeric !== undefined) {
|
|
370
|
+
console.warn("Turnkey SDK warning. You have set otpAlphanumeric directly in the TurnkeyProvider. This setting will be ignored because you are using an auth proxy. Please configure OTP settings in the Turnkey dashboard.");
|
|
371
|
+
}
|
|
372
|
+
if (config.auth?.otpLength) {
|
|
373
|
+
console.warn("Turnkey SDK warning. You have set otpLength directly in the TurnkeyProvider. This setting will be ignored because you are using an auth proxy. Please configure OTP settings in the Turnkey dashboard.");
|
|
374
|
+
}
|
|
375
|
+
// These are settings that can only be set via the auth proxy config
|
|
376
|
+
const authProxyOnlySettings = {
|
|
377
|
+
sessionExpirationSeconds: proxyAuthConfig?.sessionExpirationSeconds,
|
|
378
|
+
otpAlphanumeric: proxyAuthConfig?.otpAlphanumeric ?? true,
|
|
379
|
+
// This fallback will never be hit. This is purely for the tests to pass before mono is released
|
|
380
|
+
otpLength: proxyAuthConfig?.otpLength ?? "6" // This fallback will never be hit. This is purely for the tests to pass before mono is released
|
|
381
|
+
};
|
|
354
382
|
return {
|
|
355
383
|
...config,
|
|
356
384
|
// Overrides:
|
|
357
385
|
auth: {
|
|
358
386
|
...config.auth,
|
|
387
|
+
...authProxyOnlySettings,
|
|
359
388
|
methods: resolvedMethods,
|
|
360
389
|
oauthConfig: {
|
|
361
390
|
...config.auth?.oauthConfig,
|
|
362
|
-
|
|
391
|
+
...resolvedClientIds,
|
|
392
|
+
oauthRedirectUri: redirectUrl,
|
|
393
|
+
// on mobile we default to true since many mobile browsers
|
|
394
|
+
// (e.g. Safari) block popups
|
|
395
|
+
openOauthInPage: isMobile ? true : config.auth?.oauthConfig?.openOauthInPage
|
|
363
396
|
},
|
|
364
|
-
sessionExpirationSeconds: proxyAuthConfig?.sessionExpirationSeconds,
|
|
365
397
|
methodOrder,
|
|
366
398
|
oauthOrder,
|
|
367
399
|
autoRefreshSession: config.auth?.autoRefreshSession ?? true
|
|
368
400
|
},
|
|
401
|
+
autoRefreshManagedState: config.autoRefreshManagedState ?? true,
|
|
369
402
|
walletConfig: {
|
|
370
403
|
...config.walletConfig,
|
|
371
404
|
features: {
|
|
@@ -492,36 +525,47 @@ const ClientProvider = ({
|
|
|
492
525
|
* @internal
|
|
493
526
|
* Attach listeners for connected wallet providers so we can refresh state on changes.
|
|
494
527
|
*
|
|
495
|
-
* - Ethereum: listens for disconnect and chain
|
|
528
|
+
* - Ethereum: listens for disconnect and chain/account changes to trigger a refresh.
|
|
496
529
|
* - Solana: listens for disconnect via Wallet Standard `change` events to trigger a refresh.
|
|
497
|
-
* - WalletConnect:
|
|
530
|
+
* - WalletConnect:
|
|
531
|
+
* - listens for disconnect and other state changes via its unified `change` event
|
|
532
|
+
* - additionally listens for `pairingExpired` events (proposal expiration), in which
|
|
533
|
+
* case we re-fetch providers to refresh the pairing URI for the UI.
|
|
498
534
|
*
|
|
499
535
|
* Notes:
|
|
500
|
-
* - Only providers
|
|
501
|
-
*
|
|
536
|
+
* - Only connected providers are bound, except WalletConnect which must always register
|
|
537
|
+
* to handle proposal expiration even if no active session exists.
|
|
538
|
+
* - Since all WalletConnect providers share the same session, we only attach to one.
|
|
502
539
|
*
|
|
503
540
|
* @param walletProviders - Discovered providers; only connected ones are bound.
|
|
504
|
-
* @param
|
|
541
|
+
* @param onUpdateState - Invoked when a relevant provider event occurs.
|
|
505
542
|
* @returns Cleanup function that removes all listeners registered by this call.
|
|
506
543
|
*/
|
|
507
|
-
async function initializeWalletProviderListeners(walletProviders,
|
|
544
|
+
async function initializeWalletProviderListeners(walletProviders, onUpdateState) {
|
|
508
545
|
if (walletProviders.length === 0) return () => {};
|
|
509
546
|
const cleanups = [];
|
|
510
547
|
// we only want to initialize these listeners for connected walletProviders
|
|
511
548
|
const nativeOnly = provider => provider.interfaceType !== core.WalletInterfaceType.WalletConnect;
|
|
512
549
|
const ethProviders = masterConfig?.walletConfig?.chains.ethereum?.native ? walletProviders.filter(provider => provider.chainInfo.namespace === core.Chain.Ethereum && nativeOnly(provider) && provider.connectedAddresses.length > 0) : [];
|
|
513
550
|
const solProviders = masterConfig?.walletConfig?.chains.solana?.native ? walletProviders.filter(provider => provider.chainInfo.namespace === core.Chain.Solana && nativeOnly(provider) && provider.connectedAddresses.length > 0) : [];
|
|
514
|
-
//
|
|
515
|
-
//
|
|
516
|
-
//
|
|
517
|
-
|
|
518
|
-
|
|
551
|
+
// WalletConnect is excluded from native event wiring. Instead,
|
|
552
|
+
// it uses a unified `change` event exposed by our custom wrapper
|
|
553
|
+
//
|
|
554
|
+
// unlike native providers, we register listeners for WalletConnect
|
|
555
|
+
// even if it’s not currently “connected”. This is required so we
|
|
556
|
+
// can detect proposal expiration events and display the new regenerated
|
|
557
|
+
// URI for the UI
|
|
558
|
+
const wcProviders = walletProviders.filter(p => p.interfaceType === core.WalletInterfaceType.WalletConnect);
|
|
559
|
+
// since all WalletConnect providers share the same underlying session
|
|
560
|
+
// and emit identical events, we only attach listeners to a single provider
|
|
561
|
+
const wcProvider = wcProviders.find(p => p.interfaceType === core.WalletInterfaceType.WalletConnect);
|
|
562
|
+
function attachEthereumListeners(provider, onUpdateState) {
|
|
519
563
|
if (typeof provider.on !== "function") return;
|
|
520
|
-
const handleChainChanged = _chainId =>
|
|
521
|
-
const handleAccountsChanged = accounts => {
|
|
522
|
-
if (accounts.length === 0)
|
|
564
|
+
const handleChainChanged = async _chainId => onUpdateState();
|
|
565
|
+
const handleAccountsChanged = async accounts => {
|
|
566
|
+
if (accounts.length === 0) onUpdateState();
|
|
523
567
|
};
|
|
524
|
-
const handleDisconnect = () =>
|
|
568
|
+
const handleDisconnect = () => onUpdateState();
|
|
525
569
|
provider.on("chainChanged", handleChainChanged);
|
|
526
570
|
provider.on("accountsChanged", handleAccountsChanged);
|
|
527
571
|
provider.on("disconnect", handleDisconnect);
|
|
@@ -531,32 +575,43 @@ const ClientProvider = ({
|
|
|
531
575
|
provider.removeListener("disconnect", handleDisconnect);
|
|
532
576
|
};
|
|
533
577
|
}
|
|
534
|
-
function attachSolanaListeners(provider,
|
|
578
|
+
function attachSolanaListeners(provider, onUpdateState) {
|
|
535
579
|
const cleanups = [];
|
|
536
580
|
const walletEvents = provider?.features?.["standard:events"];
|
|
537
581
|
if (walletEvents?.on) {
|
|
538
|
-
const offChange = walletEvents.on("change", _evt => {
|
|
539
|
-
|
|
582
|
+
const offChange = walletEvents.on("change", async _evt => {
|
|
583
|
+
await onUpdateState();
|
|
540
584
|
});
|
|
541
585
|
cleanups.push(offChange);
|
|
542
586
|
}
|
|
543
587
|
return () => cleanups.forEach(fn => fn());
|
|
544
588
|
}
|
|
545
589
|
ethProviders.forEach(p => {
|
|
546
|
-
const cleanup = attachEthereumListeners(p.provider,
|
|
590
|
+
const cleanup = attachEthereumListeners(p.provider, onUpdateState);
|
|
547
591
|
if (cleanup) cleanups.push(cleanup);
|
|
548
592
|
});
|
|
549
593
|
solProviders.forEach(p => {
|
|
550
|
-
const cleanup = attachSolanaListeners(p.provider,
|
|
594
|
+
const cleanup = attachSolanaListeners(p.provider, onUpdateState);
|
|
551
595
|
if (cleanup) cleanups.push(cleanup);
|
|
552
596
|
});
|
|
553
|
-
|
|
554
|
-
const standardEvents =
|
|
597
|
+
if (wcProvider) {
|
|
598
|
+
const standardEvents = wcProvider.provider?.features?.["standard:events"];
|
|
555
599
|
if (standardEvents?.on) {
|
|
556
|
-
|
|
557
|
-
|
|
600
|
+
if (standardEvents?.on) {
|
|
601
|
+
const unsubscribe = standardEvents.on("change", async evt => {
|
|
602
|
+
// if the event is a proposalExpired, we want to re-fetch the providers
|
|
603
|
+
// to refresh the uri, there is no need to refresh the wallets state
|
|
604
|
+
if (evt?.type === "pairingExpired") {
|
|
605
|
+
debouncedFetchWalletProviders();
|
|
606
|
+
}
|
|
607
|
+
// any other event (disconnect, chain switch, accounts changed)
|
|
608
|
+
// we refresh the wallets state
|
|
609
|
+
await onUpdateState();
|
|
610
|
+
});
|
|
611
|
+
cleanups.push(unsubscribe);
|
|
612
|
+
}
|
|
558
613
|
}
|
|
559
|
-
}
|
|
614
|
+
}
|
|
560
615
|
return () => {
|
|
561
616
|
cleanups.forEach(remove => remove());
|
|
562
617
|
};
|
|
@@ -766,7 +821,7 @@ const ClientProvider = ({
|
|
|
766
821
|
}
|
|
767
822
|
return utils.withTurnkeyErrorHandling(() => client.createPasskey({
|
|
768
823
|
...params
|
|
769
|
-
}), callbacks, "Failed to create passkey");
|
|
824
|
+
}), () => logout(), callbacks, "Failed to create passkey");
|
|
770
825
|
}, [client, callbacks]);
|
|
771
826
|
const logout = react.useCallback(async params => {
|
|
772
827
|
if (!client) {
|
|
@@ -779,7 +834,7 @@ const ClientProvider = ({
|
|
|
779
834
|
await client.logout(params);
|
|
780
835
|
// We only handle post logout if the sessionKey is defined since that means we actually logged out of a session.
|
|
781
836
|
if (sessionKey) handlePostLogout(sessionKey);
|
|
782
|
-
}, callbacks, "Failed to logout");
|
|
837
|
+
}, () => logout(), callbacks, "Failed to logout");
|
|
783
838
|
return;
|
|
784
839
|
}, [client, callbacks]);
|
|
785
840
|
const loginWithPasskey = react.useCallback(async params => {
|
|
@@ -790,7 +845,7 @@ const ClientProvider = ({
|
|
|
790
845
|
const res = await utils.withTurnkeyErrorHandling(() => client.loginWithPasskey({
|
|
791
846
|
...params,
|
|
792
847
|
expirationSeconds
|
|
793
|
-
}), callbacks, "Failed to login with passkey");
|
|
848
|
+
}), () => logout(), callbacks, "Failed to login with passkey");
|
|
794
849
|
if (res) {
|
|
795
850
|
await handlePostAuth({
|
|
796
851
|
method: base.AuthMethod.Passkey,
|
|
@@ -829,7 +884,7 @@ const ClientProvider = ({
|
|
|
829
884
|
...params,
|
|
830
885
|
passkeyDisplayName: passkeyName,
|
|
831
886
|
expirationSeconds
|
|
832
|
-
}), callbacks, "Failed to sign up with passkey");
|
|
887
|
+
}), () => logout(), callbacks, "Failed to sign up with passkey");
|
|
833
888
|
if (res) {
|
|
834
889
|
await handlePostAuth({
|
|
835
890
|
method: base.AuthMethod.Passkey,
|
|
@@ -839,11 +894,11 @@ const ClientProvider = ({
|
|
|
839
894
|
}
|
|
840
895
|
return res;
|
|
841
896
|
}, [client, callbacks]);
|
|
842
|
-
const
|
|
897
|
+
const fetchWalletProviders = react.useCallback(async chain => {
|
|
843
898
|
if (!client) {
|
|
844
899
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
845
900
|
}
|
|
846
|
-
const newProviders = await client.
|
|
901
|
+
const newProviders = await client.fetchWalletProviders(chain);
|
|
847
902
|
// we update state with the latest providers
|
|
848
903
|
// we keep this state so that initializeWalletProviderListeners() re-runs
|
|
849
904
|
// whenever the list of connected providers changes
|
|
@@ -855,26 +910,34 @@ const ClientProvider = ({
|
|
|
855
910
|
if (!client) {
|
|
856
911
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
857
912
|
}
|
|
858
|
-
await client.connectWalletAccount(walletProvider);
|
|
859
|
-
|
|
860
|
-
await
|
|
913
|
+
const address = await client.connectWalletAccount(walletProvider);
|
|
914
|
+
let wallets;
|
|
915
|
+
const s = await getSession();
|
|
916
|
+
if (s) {
|
|
917
|
+
// this will update our walletProvider state
|
|
918
|
+
wallets = await refreshWallets();
|
|
919
|
+
} else {
|
|
920
|
+
wallets = await fetchWallets({
|
|
921
|
+
connectedOnly: true
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
// we narrow to only connected wallets
|
|
925
|
+
// because we know the account must come from one of them
|
|
926
|
+
const connectedWallets = wallets.filter(w => w.source === core.WalletSource.Connected);
|
|
927
|
+
// find the matching account
|
|
928
|
+
const matchedAccount = connectedWallets.flatMap(w => w.accounts).find(a => a.address === address);
|
|
929
|
+
if (!matchedAccount) {
|
|
930
|
+
throw new sdkTypes.TurnkeyError(`No connected wallet account found for address: ${address}`, sdkTypes.TurnkeyErrorCodes.NO_WALLET_FOUND);
|
|
931
|
+
}
|
|
932
|
+
return matchedAccount;
|
|
861
933
|
}, [client, callbacks]);
|
|
862
934
|
const disconnectWalletAccount = react.useCallback(async walletProvider => {
|
|
863
935
|
if (!client) {
|
|
864
936
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
865
937
|
}
|
|
866
938
|
await client.disconnectWalletAccount(walletProvider);
|
|
867
|
-
//
|
|
868
|
-
//
|
|
869
|
-
// you can disconnect a wallet before actually being logged in
|
|
870
|
-
//
|
|
871
|
-
// 2. it was a WalletConnect provider that we just disconnected. Since
|
|
872
|
-
// native providers emit a disconnect event which will already refresh
|
|
873
|
-
// the wallets. This event is triggered in `initializeWalletProviderListeners()`
|
|
874
|
-
if (session && walletProvider.interfaceType === core.WalletInterfaceType.WalletConnect) {
|
|
875
|
-
// this will update our walletProvider state
|
|
876
|
-
await refreshWallets();
|
|
877
|
-
}
|
|
939
|
+
// no need here to call `refreshWallets()` because the provider emits a disconnect event which
|
|
940
|
+
// will trigger a refresh via the listener we set up in `initializeWalletProviderListeners()`
|
|
878
941
|
}, [client, callbacks]);
|
|
879
942
|
const switchWalletAccountChain = react.useCallback(async params => {
|
|
880
943
|
if (!client) {
|
|
@@ -893,7 +956,7 @@ const ClientProvider = ({
|
|
|
893
956
|
const res = await utils.withTurnkeyErrorHandling(() => client.loginWithWallet({
|
|
894
957
|
...params,
|
|
895
958
|
expirationSeconds
|
|
896
|
-
}), callbacks, "Failed to login with wallet");
|
|
959
|
+
}), () => logout(), callbacks, "Failed to login with wallet");
|
|
897
960
|
if (res) {
|
|
898
961
|
await handlePostAuth({
|
|
899
962
|
method: base.AuthMethod.Wallet,
|
|
@@ -922,7 +985,7 @@ const ClientProvider = ({
|
|
|
922
985
|
const res = await utils.withTurnkeyErrorHandling(() => client.signUpWithWallet({
|
|
923
986
|
...params,
|
|
924
987
|
expirationSeconds
|
|
925
|
-
}), callbacks, "Failed to sign up with wallet");
|
|
988
|
+
}), () => logout(), callbacks, "Failed to sign up with wallet");
|
|
926
989
|
if (res) {
|
|
927
990
|
await handlePostAuth({
|
|
928
991
|
method: base.AuthMethod.Wallet,
|
|
@@ -951,7 +1014,7 @@ const ClientProvider = ({
|
|
|
951
1014
|
const res = await utils.withTurnkeyErrorHandling(() => client.loginOrSignupWithWallet({
|
|
952
1015
|
...params,
|
|
953
1016
|
expirationSeconds
|
|
954
|
-
}), callbacks, "Failed to login or sign up with wallet");
|
|
1017
|
+
}), () => logout(), callbacks, "Failed to login or sign up with wallet");
|
|
955
1018
|
if (res) {
|
|
956
1019
|
await handlePostAuth({
|
|
957
1020
|
method: base.AuthMethod.Wallet,
|
|
@@ -965,19 +1028,19 @@ const ClientProvider = ({
|
|
|
965
1028
|
if (!client) {
|
|
966
1029
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
967
1030
|
}
|
|
968
|
-
return utils.withTurnkeyErrorHandling(() => client.initOtp(params), callbacks, "Failed to initialize OTP");
|
|
1031
|
+
return utils.withTurnkeyErrorHandling(() => client.initOtp(params), () => logout(), callbacks, "Failed to initialize OTP");
|
|
969
1032
|
}, [client, callbacks]);
|
|
970
1033
|
const verifyOtp = react.useCallback(async params => {
|
|
971
1034
|
if (!client) {
|
|
972
1035
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
973
1036
|
}
|
|
974
|
-
return utils.withTurnkeyErrorHandling(() => client.verifyOtp(params), callbacks, "Failed to verify OTP");
|
|
1037
|
+
return utils.withTurnkeyErrorHandling(() => client.verifyOtp(params), () => logout(), callbacks, "Failed to verify OTP");
|
|
975
1038
|
}, [client, callbacks]);
|
|
976
1039
|
const loginWithOtp = react.useCallback(async params => {
|
|
977
1040
|
if (!client) {
|
|
978
1041
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
979
1042
|
}
|
|
980
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.loginWithOtp(params), callbacks, "Failed to login with OTP");
|
|
1043
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.loginWithOtp(params), () => logout(), callbacks, "Failed to login with OTP");
|
|
981
1044
|
if (res) {
|
|
982
1045
|
await handlePostAuth({
|
|
983
1046
|
method: base.AuthMethod.Otp,
|
|
@@ -1009,7 +1072,7 @@ const ClientProvider = ({
|
|
|
1009
1072
|
} : {
|
|
1010
1073
|
...params
|
|
1011
1074
|
};
|
|
1012
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.signUpWithOtp(params), callbacks, "Failed to sign up with OTP");
|
|
1075
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.signUpWithOtp(params), () => logout(), callbacks, "Failed to sign up with OTP");
|
|
1013
1076
|
if (res) {
|
|
1014
1077
|
await handlePostAuth({
|
|
1015
1078
|
method: base.AuthMethod.Otp,
|
|
@@ -1041,7 +1104,7 @@ const ClientProvider = ({
|
|
|
1041
1104
|
} : {
|
|
1042
1105
|
...params
|
|
1043
1106
|
};
|
|
1044
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.completeOtp(params), callbacks, "Failed to complete OTP");
|
|
1107
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.completeOtp(params), () => logout(), callbacks, "Failed to complete OTP");
|
|
1045
1108
|
if (res) {
|
|
1046
1109
|
await handlePostAuth({
|
|
1047
1110
|
method: base.AuthMethod.Otp,
|
|
@@ -1055,7 +1118,7 @@ const ClientProvider = ({
|
|
|
1055
1118
|
if (!client) {
|
|
1056
1119
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1057
1120
|
}
|
|
1058
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.loginWithOauth(params), callbacks, "Failed to login with OAuth");
|
|
1121
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.loginWithOauth(params), () => logout(), callbacks, "Failed to login with OAuth");
|
|
1059
1122
|
if (res) {
|
|
1060
1123
|
await handlePostAuth({
|
|
1061
1124
|
method: base.AuthMethod.Oauth,
|
|
@@ -1080,7 +1143,7 @@ const ClientProvider = ({
|
|
|
1080
1143
|
} : {
|
|
1081
1144
|
...params
|
|
1082
1145
|
};
|
|
1083
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.signUpWithOauth(params), callbacks, "Failed to sign up with OAuth");
|
|
1146
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.signUpWithOauth(params), () => logout(), callbacks, "Failed to sign up with OAuth");
|
|
1084
1147
|
if (res) {
|
|
1085
1148
|
await handlePostAuth({
|
|
1086
1149
|
method: base.AuthMethod.Oauth,
|
|
@@ -1105,7 +1168,7 @@ const ClientProvider = ({
|
|
|
1105
1168
|
} : {
|
|
1106
1169
|
...params
|
|
1107
1170
|
};
|
|
1108
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.completeOauth(params), callbacks, "Failed to complete OAuth");
|
|
1171
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.completeOauth(params), () => logout(), callbacks, "Failed to complete OAuth");
|
|
1109
1172
|
if (res) {
|
|
1110
1173
|
await handlePostAuth({
|
|
1111
1174
|
method: base.AuthMethod.Oauth,
|
|
@@ -1119,23 +1182,23 @@ const ClientProvider = ({
|
|
|
1119
1182
|
if (!client) {
|
|
1120
1183
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1121
1184
|
}
|
|
1122
|
-
return utils.withTurnkeyErrorHandling(() => client.fetchWallets(params), callbacks, "Failed to fetch wallets");
|
|
1185
|
+
return utils.withTurnkeyErrorHandling(() => client.fetchWallets(params), () => logout(), callbacks, "Failed to fetch wallets");
|
|
1123
1186
|
}, [client, callbacks]);
|
|
1124
1187
|
const fetchWalletAccounts = react.useCallback(async params => {
|
|
1125
1188
|
if (!client) {
|
|
1126
1189
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1127
1190
|
}
|
|
1128
|
-
return utils.withTurnkeyErrorHandling(() => client.fetchWalletAccounts(params), callbacks, "Failed to fetch wallet accounts");
|
|
1191
|
+
return utils.withTurnkeyErrorHandling(() => client.fetchWalletAccounts(params), () => logout(), callbacks, "Failed to fetch wallet accounts");
|
|
1129
1192
|
}, [client, callbacks]);
|
|
1130
1193
|
const fetchPrivateKeys = react.useCallback(async params => {
|
|
1131
1194
|
if (!client) {
|
|
1132
1195
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1133
1196
|
}
|
|
1134
|
-
return utils.withTurnkeyErrorHandling(() => client.fetchPrivateKeys(params), callbacks, "Failed to fetch private keys");
|
|
1197
|
+
return utils.withTurnkeyErrorHandling(() => client.fetchPrivateKeys(params), () => logout(), callbacks, "Failed to fetch private keys");
|
|
1135
1198
|
}, [client, callbacks]);
|
|
1136
1199
|
const signMessage = react.useCallback(async params => {
|
|
1137
1200
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1138
|
-
return utils.withTurnkeyErrorHandling(() => client.signMessage(params), callbacks, "Failed to sign message");
|
|
1201
|
+
return utils.withTurnkeyErrorHandling(() => client.signMessage(params), () => logout(), callbacks, "Failed to sign message");
|
|
1139
1202
|
}, [client, callbacks]);
|
|
1140
1203
|
const handleSignMessage = react.useCallback(async params => {
|
|
1141
1204
|
const {
|
|
@@ -1165,6 +1228,9 @@ const ClientProvider = ({
|
|
|
1165
1228
|
}),
|
|
1166
1229
|
...(params?.addEthereumPrefix && {
|
|
1167
1230
|
addEthereumPrefix: params.addEthereumPrefix
|
|
1231
|
+
}),
|
|
1232
|
+
...(params?.organizationId && {
|
|
1233
|
+
organizationId: params.organizationId
|
|
1168
1234
|
})
|
|
1169
1235
|
})
|
|
1170
1236
|
});
|
|
@@ -1172,145 +1238,230 @@ const ClientProvider = ({
|
|
|
1172
1238
|
}, [client, callbacks]);
|
|
1173
1239
|
const signTransaction = react.useCallback(async params => {
|
|
1174
1240
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1175
|
-
return utils.withTurnkeyErrorHandling(() => client.signTransaction(params), callbacks, "Failed to sign transaction");
|
|
1241
|
+
return utils.withTurnkeyErrorHandling(() => client.signTransaction(params), () => logout(), callbacks, "Failed to sign transaction");
|
|
1176
1242
|
}, [client, callbacks]);
|
|
1177
1243
|
const signAndSendTransaction = react.useCallback(async params => {
|
|
1178
1244
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1179
|
-
return utils.withTurnkeyErrorHandling(() => client.signAndSendTransaction(params), callbacks, "Failed to sign transaction");
|
|
1245
|
+
return utils.withTurnkeyErrorHandling(() => client.signAndSendTransaction(params), () => logout(), callbacks, "Failed to sign transaction");
|
|
1180
1246
|
}, [client, callbacks]);
|
|
1181
1247
|
const fetchUser = react.useCallback(async params => {
|
|
1182
1248
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1183
|
-
return utils.withTurnkeyErrorHandling(() => client.fetchUser(params), callbacks, "Failed to fetch user");
|
|
1249
|
+
return utils.withTurnkeyErrorHandling(() => client.fetchUser(params), () => logout(), callbacks, "Failed to fetch user");
|
|
1250
|
+
}, [client, callbacks]);
|
|
1251
|
+
const fetchOrCreateP256ApiKeyUser = react.useCallback(async params => {
|
|
1252
|
+
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1253
|
+
return utils.withTurnkeyErrorHandling(() => client.fetchOrCreateP256ApiKeyUser(params), () => logout(), callbacks, "Failed to fetch or create delegated access user");
|
|
1254
|
+
}, [client, callbacks]);
|
|
1255
|
+
const fetchOrCreatePolicies = react.useCallback(async params => {
|
|
1256
|
+
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1257
|
+
return utils.withTurnkeyErrorHandling(() => client.fetchOrCreatePolicies(params), () => logout(), callbacks, "Failed to fetch or create delegated access user");
|
|
1184
1258
|
}, [client, callbacks]);
|
|
1185
1259
|
const updateUserEmail = react.useCallback(async params => {
|
|
1186
1260
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1187
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.updateUserEmail(params), callbacks, "Failed to update user email");
|
|
1261
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.updateUserEmail(params), () => logout(), callbacks, "Failed to update user email");
|
|
1188
1262
|
if (res) await refreshUser({
|
|
1189
|
-
stampWith: params?.stampWith
|
|
1263
|
+
stampWith: params?.stampWith,
|
|
1264
|
+
...(params?.organizationId && {
|
|
1265
|
+
organizationId: params.organizationId
|
|
1266
|
+
}),
|
|
1267
|
+
...(params?.userId && {
|
|
1268
|
+
userId: params.userId
|
|
1269
|
+
})
|
|
1190
1270
|
});
|
|
1191
1271
|
return res;
|
|
1192
1272
|
}, [client, callbacks]);
|
|
1193
1273
|
const removeUserEmail = react.useCallback(async params => {
|
|
1194
1274
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1195
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.removeUserEmail(params), callbacks, "Failed to remove user email");
|
|
1275
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.removeUserEmail(params), () => logout(), callbacks, "Failed to remove user email");
|
|
1196
1276
|
if (res) await refreshUser({
|
|
1197
|
-
stampWith: params?.stampWith
|
|
1277
|
+
stampWith: params?.stampWith,
|
|
1278
|
+
...(params?.organizationId && {
|
|
1279
|
+
organizationId: params.organizationId
|
|
1280
|
+
}),
|
|
1281
|
+
...(params?.userId && {
|
|
1282
|
+
userId: params.userId
|
|
1283
|
+
})
|
|
1198
1284
|
});
|
|
1199
1285
|
return res;
|
|
1200
1286
|
}, [client, callbacks]);
|
|
1201
1287
|
const updateUserPhoneNumber = react.useCallback(async params => {
|
|
1202
1288
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1203
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.updateUserPhoneNumber(params), callbacks, "Failed to update user phone number");
|
|
1289
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.updateUserPhoneNumber(params), () => logout(), callbacks, "Failed to update user phone number");
|
|
1204
1290
|
if (res) await refreshUser({
|
|
1205
|
-
stampWith: params?.stampWith
|
|
1291
|
+
stampWith: params?.stampWith,
|
|
1292
|
+
...(params?.organizationId && {
|
|
1293
|
+
organizationId: params.organizationId
|
|
1294
|
+
}),
|
|
1295
|
+
...(params?.userId && {
|
|
1296
|
+
userId: params.userId
|
|
1297
|
+
})
|
|
1206
1298
|
});
|
|
1207
1299
|
return res;
|
|
1208
1300
|
}, [client, callbacks]);
|
|
1209
1301
|
const removeUserPhoneNumber = react.useCallback(async params => {
|
|
1210
1302
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1211
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.removeUserPhoneNumber(params), callbacks, "Failed to remove user phone number");
|
|
1303
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.removeUserPhoneNumber(params), () => logout(), callbacks, "Failed to remove user phone number");
|
|
1212
1304
|
if (res) await refreshUser({
|
|
1213
|
-
stampWith: params?.stampWith
|
|
1305
|
+
stampWith: params?.stampWith,
|
|
1306
|
+
...(params?.organizationId && {
|
|
1307
|
+
organizationId: params.organizationId
|
|
1308
|
+
}),
|
|
1309
|
+
...(params?.userId && {
|
|
1310
|
+
userId: params.userId
|
|
1311
|
+
})
|
|
1214
1312
|
});
|
|
1215
1313
|
return res;
|
|
1216
1314
|
}, [client, callbacks]);
|
|
1217
1315
|
const updateUserName = react.useCallback(async params => {
|
|
1218
1316
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1219
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.updateUserName(params), callbacks, "Failed to update user name");
|
|
1317
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.updateUserName(params), () => logout(), callbacks, "Failed to update user name");
|
|
1220
1318
|
if (res) await refreshUser({
|
|
1221
|
-
stampWith: params?.stampWith
|
|
1319
|
+
stampWith: params?.stampWith,
|
|
1320
|
+
...(params?.organizationId && {
|
|
1321
|
+
organizationId: params.organizationId
|
|
1322
|
+
}),
|
|
1323
|
+
...(params?.userId && {
|
|
1324
|
+
userId: params.userId
|
|
1325
|
+
})
|
|
1222
1326
|
});
|
|
1223
1327
|
return res;
|
|
1224
1328
|
}, [client, callbacks]);
|
|
1225
1329
|
const addOauthProvider = react.useCallback(async params => {
|
|
1226
1330
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1227
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.addOauthProvider(params), callbacks, "Failed to add OAuth provider");
|
|
1331
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.addOauthProvider(params), () => logout(), callbacks, "Failed to add OAuth provider");
|
|
1228
1332
|
if (res) await refreshUser({
|
|
1229
|
-
stampWith: params?.stampWith
|
|
1333
|
+
stampWith: params?.stampWith,
|
|
1334
|
+
...(params?.organizationId && {
|
|
1335
|
+
organizationId: params.organizationId
|
|
1336
|
+
}),
|
|
1337
|
+
...(params?.userId && {
|
|
1338
|
+
userId: params.userId
|
|
1339
|
+
})
|
|
1230
1340
|
});
|
|
1231
1341
|
return res;
|
|
1232
1342
|
}, [client, callbacks]);
|
|
1233
1343
|
const removeOauthProviders = react.useCallback(async params => {
|
|
1234
1344
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1235
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.removeOauthProviders(params), callbacks, "Failed to remove OAuth providers");
|
|
1345
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.removeOauthProviders(params), () => logout(), callbacks, "Failed to remove OAuth providers");
|
|
1236
1346
|
if (res) await refreshUser({
|
|
1237
|
-
stampWith: params?.stampWith
|
|
1347
|
+
stampWith: params?.stampWith,
|
|
1348
|
+
...(params?.organizationId && {
|
|
1349
|
+
organizationId: params.organizationId
|
|
1350
|
+
}),
|
|
1351
|
+
...(params?.userId && {
|
|
1352
|
+
userId: params.userId
|
|
1353
|
+
})
|
|
1238
1354
|
});
|
|
1239
1355
|
return res;
|
|
1240
1356
|
}, [client, callbacks]);
|
|
1241
1357
|
const addPasskey = react.useCallback(async params => {
|
|
1242
1358
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1243
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.addPasskey(params), callbacks, "Failed to add passkey");
|
|
1359
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.addPasskey(params), () => logout(), callbacks, "Failed to add passkey");
|
|
1244
1360
|
if (res) await refreshUser({
|
|
1245
|
-
stampWith: params?.stampWith
|
|
1361
|
+
stampWith: params?.stampWith,
|
|
1362
|
+
...(params?.organizationId && {
|
|
1363
|
+
organizationId: params.organizationId
|
|
1364
|
+
}),
|
|
1365
|
+
...(params?.userId && {
|
|
1366
|
+
userId: params.userId
|
|
1367
|
+
})
|
|
1246
1368
|
});
|
|
1247
1369
|
return res;
|
|
1248
1370
|
}, [client, callbacks]);
|
|
1249
1371
|
const removePasskeys = react.useCallback(async params => {
|
|
1250
1372
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1251
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.removePasskeys(params), callbacks, "Failed to remove passkeys");
|
|
1373
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.removePasskeys(params), () => logout(), callbacks, "Failed to remove passkeys");
|
|
1252
1374
|
if (res) await refreshUser({
|
|
1253
|
-
stampWith: params?.stampWith
|
|
1375
|
+
stampWith: params?.stampWith,
|
|
1376
|
+
...(params?.organizationId && {
|
|
1377
|
+
organizationId: params.organizationId
|
|
1378
|
+
}),
|
|
1379
|
+
...(params?.userId && {
|
|
1380
|
+
userId: params.userId
|
|
1381
|
+
})
|
|
1254
1382
|
});
|
|
1255
1383
|
return res;
|
|
1256
1384
|
}, [client, callbacks]);
|
|
1257
1385
|
const createWallet = react.useCallback(async params => {
|
|
1258
1386
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1259
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.createWallet(params), callbacks, "Failed to create wallet");
|
|
1260
|
-
|
|
1261
|
-
|
|
1387
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.createWallet(params), () => logout(), callbacks, "Failed to create wallet");
|
|
1388
|
+
const s = await getSession();
|
|
1389
|
+
if (res && s) await refreshWallets({
|
|
1390
|
+
stampWith: params?.stampWith,
|
|
1391
|
+
...(params?.organizationId && {
|
|
1392
|
+
organizationId: params.organizationId
|
|
1393
|
+
})
|
|
1262
1394
|
});
|
|
1263
1395
|
return res;
|
|
1264
|
-
}, [client, callbacks]);
|
|
1396
|
+
}, [client, session, callbacks]);
|
|
1265
1397
|
const createWalletAccounts = react.useCallback(async params => {
|
|
1266
1398
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1267
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.createWalletAccounts(params), callbacks, "Failed to create wallet accounts");
|
|
1268
|
-
|
|
1269
|
-
|
|
1399
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.createWalletAccounts(params), () => logout(), callbacks, "Failed to create wallet accounts");
|
|
1400
|
+
const s = await getSession();
|
|
1401
|
+
if (res && s) await refreshWallets({
|
|
1402
|
+
stampWith: params?.stampWith,
|
|
1403
|
+
...(params?.organizationId && {
|
|
1404
|
+
organizationId: params.organizationId
|
|
1405
|
+
})
|
|
1270
1406
|
});
|
|
1271
1407
|
return res;
|
|
1272
|
-
}, [client, callbacks]);
|
|
1408
|
+
}, [client, session, callbacks]);
|
|
1273
1409
|
const exportWallet = react.useCallback(async params => {
|
|
1274
1410
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1275
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.exportWallet(params), callbacks, "Failed to export wallet");
|
|
1276
|
-
|
|
1277
|
-
|
|
1411
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.exportWallet(params), () => logout(), callbacks, "Failed to export wallet");
|
|
1412
|
+
const s = await getSession();
|
|
1413
|
+
if (res && s) await refreshWallets({
|
|
1414
|
+
stampWith: params?.stampWith,
|
|
1415
|
+
...(params?.organizationId && {
|
|
1416
|
+
organizationId: params.organizationId
|
|
1417
|
+
})
|
|
1278
1418
|
});
|
|
1279
1419
|
return res;
|
|
1280
|
-
}, [client, callbacks]);
|
|
1420
|
+
}, [client, session, callbacks]);
|
|
1281
1421
|
const exportPrivateKey = react.useCallback(async params => {
|
|
1282
1422
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1283
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.exportPrivateKey(params), callbacks, "Failed to export private key");
|
|
1423
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.exportPrivateKey(params), () => logout(), callbacks, "Failed to export private key");
|
|
1284
1424
|
return res;
|
|
1285
1425
|
}, [client, callbacks]);
|
|
1286
1426
|
const exportWalletAccount = react.useCallback(async params => {
|
|
1287
1427
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1288
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.exportWalletAccount(params), callbacks, "Failed to export wallet accounts");
|
|
1289
|
-
|
|
1290
|
-
|
|
1428
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.exportWalletAccount(params), () => logout(), callbacks, "Failed to export wallet accounts");
|
|
1429
|
+
const s = await getSession();
|
|
1430
|
+
if (res && s) await refreshWallets({
|
|
1431
|
+
stampWith: params?.stampWith,
|
|
1432
|
+
...(params?.organizationId && {
|
|
1433
|
+
organizationId: params.organizationId
|
|
1434
|
+
})
|
|
1291
1435
|
});
|
|
1292
1436
|
return res;
|
|
1293
|
-
}, [client, callbacks]);
|
|
1437
|
+
}, [client, callbacks, masterConfig, session, user]);
|
|
1294
1438
|
const importWallet = react.useCallback(async params => {
|
|
1295
1439
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1296
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.importWallet(params), callbacks, "Failed to import wallet");
|
|
1297
|
-
|
|
1298
|
-
|
|
1440
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.importWallet(params), () => logout(), callbacks, "Failed to import wallet");
|
|
1441
|
+
const s = await getSession();
|
|
1442
|
+
if (res && s) await refreshWallets({
|
|
1443
|
+
stampWith: params?.stampWith,
|
|
1444
|
+
...(params?.organizationId && {
|
|
1445
|
+
organizationId: params.organizationId
|
|
1446
|
+
}),
|
|
1447
|
+
...(params?.userId && {
|
|
1448
|
+
userId: params.userId
|
|
1449
|
+
})
|
|
1299
1450
|
});
|
|
1300
1451
|
return res;
|
|
1301
|
-
}, [client, callbacks]);
|
|
1452
|
+
}, [client, callbacks, masterConfig, session, user]);
|
|
1302
1453
|
const importPrivateKey = react.useCallback(async params => {
|
|
1303
1454
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1304
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.importPrivateKey(params), callbacks, "Failed to import private key");
|
|
1455
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.importPrivateKey(params), () => logout(), callbacks, "Failed to import private key");
|
|
1305
1456
|
return res;
|
|
1306
|
-
}, [client, callbacks]);
|
|
1457
|
+
}, [client, callbacks, masterConfig, session, user]);
|
|
1307
1458
|
const deleteSubOrganization = react.useCallback(async params => {
|
|
1308
1459
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1309
|
-
return utils.withTurnkeyErrorHandling(() => client.deleteSubOrganization(params), callbacks, "Failed to delete sub-organization");
|
|
1310
|
-
}, [client, callbacks]);
|
|
1460
|
+
return utils.withTurnkeyErrorHandling(() => client.deleteSubOrganization(params), () => logout(), callbacks, "Failed to delete sub-organization");
|
|
1461
|
+
}, [client, callbacks, masterConfig, session, user]);
|
|
1311
1462
|
const storeSession = react.useCallback(async params => {
|
|
1312
1463
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1313
|
-
await utils.withTurnkeyErrorHandling(() => client.storeSession(params), callbacks, "Failed to store session");
|
|
1464
|
+
await utils.withTurnkeyErrorHandling(() => client.storeSession(params), () => logout(), callbacks, "Failed to store session");
|
|
1314
1465
|
const sessionKey = await getActiveSessionKey();
|
|
1315
1466
|
const session = await getSession({
|
|
1316
1467
|
...(sessionKey && {
|
|
@@ -1325,22 +1476,33 @@ const ClientProvider = ({
|
|
|
1325
1476
|
setSession(session);
|
|
1326
1477
|
setAllSessions(allSessions);
|
|
1327
1478
|
return;
|
|
1328
|
-
}, [client, callbacks]);
|
|
1479
|
+
}, [client, callbacks, masterConfig, session, user]);
|
|
1329
1480
|
const clearSession = react.useCallback(async params => {
|
|
1330
1481
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1331
|
-
await utils.withTurnkeyErrorHandling(() => client.clearSession(params), callbacks, "Failed to clear session");
|
|
1332
|
-
const
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1482
|
+
await utils.withTurnkeyErrorHandling(async () => client.clearSession(params), () => logout(), callbacks, "Failed to clear session");
|
|
1483
|
+
const sessionKey = params?.sessionKey ?? (await getActiveSessionKey());
|
|
1484
|
+
if (!sessionKey) return;
|
|
1485
|
+
if (!params?.sessionKey) {
|
|
1486
|
+
setSession(undefined);
|
|
1487
|
+
}
|
|
1488
|
+
clearSessionTimeouts([sessionKey]);
|
|
1489
|
+
// clear only the cleared session from allSessions
|
|
1490
|
+
const newAllSessions = {
|
|
1491
|
+
...allSessions
|
|
1492
|
+
};
|
|
1493
|
+
if (newAllSessions) {
|
|
1494
|
+
delete newAllSessions[sessionKey];
|
|
1495
|
+
}
|
|
1496
|
+
setAllSessions(newAllSessions);
|
|
1336
1497
|
return;
|
|
1337
|
-
}, [client, callbacks]);
|
|
1498
|
+
}, [client, callbacks, session, user, masterConfig]);
|
|
1338
1499
|
const clearAllSessions = react.useCallback(async () => {
|
|
1339
1500
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1340
1501
|
setSession(undefined);
|
|
1341
1502
|
setAllSessions(undefined);
|
|
1342
|
-
|
|
1343
|
-
|
|
1503
|
+
clearSessionTimeouts();
|
|
1504
|
+
return await utils.withTurnkeyErrorHandling(() => client.clearAllSessions(), () => logout(), callbacks, "Failed to clear all sessions");
|
|
1505
|
+
}, [client, callbacks, session, user, masterConfig]);
|
|
1344
1506
|
const refreshSession = react.useCallback(async params => {
|
|
1345
1507
|
if (!client) {
|
|
1346
1508
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
@@ -1352,7 +1514,7 @@ const ClientProvider = ({
|
|
|
1352
1514
|
const sessionKey = params?.sessionKey ?? activeSessionKey;
|
|
1353
1515
|
const res = await utils.withTurnkeyErrorHandling(() => client.refreshSession({
|
|
1354
1516
|
...params
|
|
1355
|
-
}), callbacks, "Failed to refresh session");
|
|
1517
|
+
}), () => logout(), callbacks, "Failed to refresh session");
|
|
1356
1518
|
const session = await getSession({
|
|
1357
1519
|
sessionKey
|
|
1358
1520
|
});
|
|
@@ -1369,73 +1531,93 @@ const ClientProvider = ({
|
|
|
1369
1531
|
setSession(session);
|
|
1370
1532
|
setAllSessions(allSessions);
|
|
1371
1533
|
return res;
|
|
1372
|
-
}, [client, callbacks]);
|
|
1534
|
+
}, [client, callbacks, scheduleSessionExpiration, session, user, masterConfig]);
|
|
1373
1535
|
const getSession = react.useCallback(async params => {
|
|
1374
1536
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1375
|
-
return utils.withTurnkeyErrorHandling(() => client.getSession(params), callbacks, "Failed to get session");
|
|
1376
|
-
}, [client, callbacks]);
|
|
1537
|
+
return utils.withTurnkeyErrorHandling(() => client.getSession(params), () => logout(), callbacks, "Failed to get session");
|
|
1538
|
+
}, [client, callbacks, masterConfig, session, user]);
|
|
1377
1539
|
const getAllSessions = react.useCallback(async () => {
|
|
1378
1540
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1379
|
-
return utils.withTurnkeyErrorHandling(() => client.getAllSessions(), callbacks, "Failed to get all sessions");
|
|
1380
|
-
}, [client, callbacks]);
|
|
1541
|
+
return utils.withTurnkeyErrorHandling(() => client.getAllSessions(), () => logout(), callbacks, "Failed to get all sessions");
|
|
1542
|
+
}, [client, callbacks, masterConfig, session, user]);
|
|
1381
1543
|
const setActiveSession = react.useCallback(async params => {
|
|
1382
1544
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1383
1545
|
const session = await utils.withTurnkeyErrorHandling(() => client.getSession({
|
|
1384
1546
|
sessionKey: params.sessionKey
|
|
1385
|
-
}), callbacks, "Failed to get session");
|
|
1386
|
-
|
|
1547
|
+
}), () => logout(), callbacks, "Failed to get session");
|
|
1548
|
+
const s = await getSession();
|
|
1549
|
+
if (!s) {
|
|
1387
1550
|
throw new sdkTypes.TurnkeyError("Session not found.", sdkTypes.TurnkeyErrorCodes.NOT_FOUND);
|
|
1388
1551
|
}
|
|
1389
|
-
await utils.withTurnkeyErrorHandling(() => client.setActiveSession(params), callbacks, "Failed to set active session");
|
|
1552
|
+
await utils.withTurnkeyErrorHandling(() => client.setActiveSession(params), () => logout(), callbacks, "Failed to set active session");
|
|
1390
1553
|
setSession(session);
|
|
1391
1554
|
await utils.withTurnkeyErrorHandling(async () => {
|
|
1392
1555
|
await refreshWallets();
|
|
1393
1556
|
await refreshUser();
|
|
1394
|
-
}, callbacks, "Failed to refresh data after setting active session");
|
|
1557
|
+
}, () => logout(), callbacks, "Failed to refresh data after setting active session");
|
|
1395
1558
|
return;
|
|
1396
|
-
}, [client, callbacks]);
|
|
1559
|
+
}, [client, callbacks, session, user, masterConfig]);
|
|
1397
1560
|
const getActiveSessionKey = react.useCallback(async () => {
|
|
1398
1561
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1399
|
-
return utils.withTurnkeyErrorHandling(() => client.getActiveSessionKey(), callbacks, "Failed to get active session key");
|
|
1400
|
-
}, [client, callbacks]);
|
|
1562
|
+
return utils.withTurnkeyErrorHandling(() => client.getActiveSessionKey(), () => logout(), callbacks, "Failed to get active session key");
|
|
1563
|
+
}, [client, callbacks, masterConfig, session, user]);
|
|
1401
1564
|
const clearUnusedKeyPairs = react.useCallback(async () => {
|
|
1402
1565
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1403
|
-
return utils.withTurnkeyErrorHandling(() => client.clearUnusedKeyPairs(), callbacks, "Failed to clear unused key pairs");
|
|
1404
|
-
}, [client, callbacks]);
|
|
1566
|
+
return utils.withTurnkeyErrorHandling(() => client.clearUnusedKeyPairs(), () => logout(), callbacks, "Failed to clear unused key pairs");
|
|
1567
|
+
}, [client, callbacks, masterConfig, session, user]);
|
|
1405
1568
|
const createApiKeyPair = react.useCallback(async params => {
|
|
1406
1569
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1407
|
-
return utils.withTurnkeyErrorHandling(() => client.createApiKeyPair(params), callbacks, "Failed to create API key pair");
|
|
1408
|
-
}, [client, callbacks]);
|
|
1570
|
+
return utils.withTurnkeyErrorHandling(() => client.createApiKeyPair(params), () => logout(), callbacks, "Failed to create API key pair");
|
|
1571
|
+
}, [client, callbacks, session, user, masterConfig]);
|
|
1409
1572
|
const getProxyAuthConfig = react.useCallback(async () => {
|
|
1410
1573
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1411
|
-
return utils.withTurnkeyErrorHandling(() => client.getProxyAuthConfig(), callbacks, "Failed to get proxy auth config");
|
|
1412
|
-
}, [client, callbacks]);
|
|
1574
|
+
return utils.withTurnkeyErrorHandling(() => client.getProxyAuthConfig(), () => logout(), callbacks, "Failed to get proxy auth config");
|
|
1575
|
+
}, [client, callbacks, masterConfig, session, user]);
|
|
1413
1576
|
const refreshUser = react.useCallback(async params => {
|
|
1577
|
+
if (!masterConfig?.autoRefreshManagedState) return;
|
|
1414
1578
|
const {
|
|
1415
|
-
stampWith
|
|
1579
|
+
stampWith,
|
|
1580
|
+
organizationId,
|
|
1581
|
+
userId
|
|
1416
1582
|
} = params || {};
|
|
1417
1583
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1418
1584
|
const user = await utils.withTurnkeyErrorHandling(() => fetchUser({
|
|
1419
|
-
stampWith
|
|
1420
|
-
|
|
1585
|
+
stampWith,
|
|
1586
|
+
...(organizationId && {
|
|
1587
|
+
organizationId
|
|
1588
|
+
}),
|
|
1589
|
+
...(userId && {
|
|
1590
|
+
userId
|
|
1591
|
+
})
|
|
1592
|
+
}), () => logout(), callbacks, "Failed to refresh user");
|
|
1421
1593
|
if (user) {
|
|
1422
1594
|
setUser(user);
|
|
1423
1595
|
}
|
|
1424
|
-
}, [client, callbacks]);
|
|
1596
|
+
}, [client, callbacks, fetchUser, masterConfig, session, user]);
|
|
1425
1597
|
const refreshWallets = react.useCallback(async params => {
|
|
1598
|
+
if (!masterConfig?.autoRefreshManagedState) return [];
|
|
1426
1599
|
const {
|
|
1427
|
-
stampWith
|
|
1600
|
+
stampWith,
|
|
1601
|
+
organizationId,
|
|
1602
|
+
userId
|
|
1428
1603
|
} = params || {};
|
|
1429
1604
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1430
|
-
const walletProviders = await utils.withTurnkeyErrorHandling(() =>
|
|
1605
|
+
const walletProviders = await utils.withTurnkeyErrorHandling(() => fetchWalletProviders(), () => logout(), callbacks, "Failed to refresh wallets");
|
|
1431
1606
|
const wallets = await utils.withTurnkeyErrorHandling(() => fetchWallets({
|
|
1432
1607
|
stampWith,
|
|
1433
|
-
walletProviders
|
|
1434
|
-
|
|
1608
|
+
walletProviders,
|
|
1609
|
+
...(organizationId && {
|
|
1610
|
+
organizationId
|
|
1611
|
+
}),
|
|
1612
|
+
...(userId && {
|
|
1613
|
+
userId
|
|
1614
|
+
})
|
|
1615
|
+
}), () => logout(), callbacks, "Failed to refresh wallets");
|
|
1435
1616
|
if (wallets) {
|
|
1436
1617
|
setWallets(wallets);
|
|
1437
1618
|
}
|
|
1438
|
-
|
|
1619
|
+
return wallets;
|
|
1620
|
+
}, [client, callbacks, fetchWalletProviders, fetchWallets, masterConfig, session, user]);
|
|
1439
1621
|
const handleDiscordOauth = react.useCallback(async params => {
|
|
1440
1622
|
const {
|
|
1441
1623
|
clientId = masterConfig?.auth?.oauthConfig?.discordClientId,
|
|
@@ -1526,6 +1708,7 @@ const ClientProvider = ({
|
|
|
1526
1708
|
authCode,
|
|
1527
1709
|
redirectUri: redirectURI,
|
|
1528
1710
|
codeVerifier: verifier,
|
|
1711
|
+
clientId,
|
|
1529
1712
|
nonce: nonce
|
|
1530
1713
|
}).then(resp => {
|
|
1531
1714
|
sessionStorage.removeItem("discord_verifier");
|
|
@@ -1573,7 +1756,7 @@ const ClientProvider = ({
|
|
|
1573
1756
|
} catch (error) {
|
|
1574
1757
|
throw error;
|
|
1575
1758
|
}
|
|
1576
|
-
}, [client, callbacks]);
|
|
1759
|
+
}, [client, callbacks, completeOauth, createApiKeyPair, masterConfig, session, user]);
|
|
1577
1760
|
const handleXOauth = react.useCallback(async params => {
|
|
1578
1761
|
const {
|
|
1579
1762
|
clientId = masterConfig?.auth?.oauthConfig?.xClientId,
|
|
@@ -1664,6 +1847,7 @@ const ClientProvider = ({
|
|
|
1664
1847
|
authCode,
|
|
1665
1848
|
redirectUri: redirectURI,
|
|
1666
1849
|
codeVerifier: verifier,
|
|
1850
|
+
clientId,
|
|
1667
1851
|
nonce
|
|
1668
1852
|
}).then(resp => {
|
|
1669
1853
|
sessionStorage.removeItem("twitter_verifier");
|
|
@@ -1711,7 +1895,7 @@ const ClientProvider = ({
|
|
|
1711
1895
|
} catch (error) {
|
|
1712
1896
|
throw error;
|
|
1713
1897
|
}
|
|
1714
|
-
}, [client, callbacks]);
|
|
1898
|
+
}, [client, callbacks, masterConfig, session, user]);
|
|
1715
1899
|
const handleGoogleOauth = react.useCallback(async params => {
|
|
1716
1900
|
const {
|
|
1717
1901
|
clientId = masterConfig?.auth?.oauthConfig?.googleClientId,
|
|
@@ -1839,7 +2023,7 @@ const ClientProvider = ({
|
|
|
1839
2023
|
} catch (error) {
|
|
1840
2024
|
throw error;
|
|
1841
2025
|
}
|
|
1842
|
-
}, [client, callbacks]);
|
|
2026
|
+
}, [client, callbacks, masterConfig, session, user]);
|
|
1843
2027
|
const handleAppleOauth = react.useCallback(async params => {
|
|
1844
2028
|
const {
|
|
1845
2029
|
clientId = masterConfig?.auth?.oauthConfig?.appleClientId,
|
|
@@ -1963,7 +2147,7 @@ const ClientProvider = ({
|
|
|
1963
2147
|
} catch (error) {
|
|
1964
2148
|
throw error;
|
|
1965
2149
|
}
|
|
1966
|
-
}, [client, callbacks]);
|
|
2150
|
+
}, [client, callbacks, masterConfig, session, user]);
|
|
1967
2151
|
const handleFacebookOauth = react.useCallback(async params => {
|
|
1968
2152
|
const {
|
|
1969
2153
|
clientId = masterConfig?.auth?.oauthConfig?.facebookClientId,
|
|
@@ -2105,88 +2289,114 @@ const ClientProvider = ({
|
|
|
2105
2289
|
} catch (error) {
|
|
2106
2290
|
throw error;
|
|
2107
2291
|
}
|
|
2108
|
-
}, [client, callbacks]);
|
|
2292
|
+
}, [client, callbacks, masterConfig, client, session, user]);
|
|
2109
2293
|
const handleLogin = react.useCallback(async params => {
|
|
2294
|
+
const logo = masterConfig?.ui?.darkMode ? params?.logoDark ?? masterConfig?.ui?.logoDark : params?.logoLight ?? masterConfig?.ui?.logoLight;
|
|
2110
2295
|
pushPage({
|
|
2111
|
-
key: "Log in or sign up",
|
|
2296
|
+
key: params?.title ?? "Log in or sign up",
|
|
2112
2297
|
content: jsxRuntime.jsx(index.AuthComponent, {
|
|
2113
|
-
sessionKey: params?.sessionKey
|
|
2114
|
-
|
|
2298
|
+
sessionKey: params?.sessionKey,
|
|
2299
|
+
logo: logo,
|
|
2300
|
+
logoClassName: params?.logoClassName,
|
|
2301
|
+
title: params?.title
|
|
2302
|
+
}),
|
|
2303
|
+
showTitle: logo ? false : true
|
|
2115
2304
|
});
|
|
2116
|
-
}, [pushPage]);
|
|
2305
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2117
2306
|
const handleExportWallet = react.useCallback(async params => {
|
|
2118
2307
|
const {
|
|
2119
2308
|
walletId,
|
|
2120
2309
|
targetPublicKey,
|
|
2121
|
-
stampWith
|
|
2310
|
+
stampWith,
|
|
2311
|
+
organizationId
|
|
2122
2312
|
} = params;
|
|
2123
|
-
pushPage({
|
|
2313
|
+
return new Promise((resolve, reject) => pushPage({
|
|
2124
2314
|
key: "Export wallet",
|
|
2125
2315
|
content: jsxRuntime.jsx(Export.ExportComponent, {
|
|
2126
2316
|
target: walletId,
|
|
2127
2317
|
exportType: base.ExportType.Wallet,
|
|
2128
|
-
...(targetPublicKey !== undefined
|
|
2318
|
+
...(targetPublicKey !== undefined && {
|
|
2129
2319
|
targetPublicKey
|
|
2130
|
-
}
|
|
2131
|
-
...(stampWith !== undefined
|
|
2320
|
+
}),
|
|
2321
|
+
...(stampWith !== undefined && {
|
|
2132
2322
|
stampWith
|
|
2133
|
-
}
|
|
2323
|
+
}),
|
|
2324
|
+
...(organizationId !== undefined && {
|
|
2325
|
+
organizationId
|
|
2326
|
+
}),
|
|
2327
|
+
onSuccess: () => resolve(),
|
|
2328
|
+
onError: error => reject(error)
|
|
2134
2329
|
})
|
|
2135
|
-
});
|
|
2136
|
-
}, [pushPage]);
|
|
2330
|
+
}));
|
|
2331
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2137
2332
|
const handleExportPrivateKey = react.useCallback(async params => {
|
|
2138
2333
|
const {
|
|
2139
2334
|
privateKeyId,
|
|
2140
2335
|
targetPublicKey,
|
|
2141
2336
|
keyFormat,
|
|
2142
|
-
stampWith
|
|
2337
|
+
stampWith,
|
|
2338
|
+
organizationId
|
|
2143
2339
|
} = params;
|
|
2144
|
-
pushPage({
|
|
2340
|
+
return new Promise((resolve, reject) => pushPage({
|
|
2145
2341
|
key: "Export private key",
|
|
2146
2342
|
content: jsxRuntime.jsx(Export.ExportComponent, {
|
|
2147
2343
|
target: privateKeyId,
|
|
2148
2344
|
exportType: base.ExportType.PrivateKey,
|
|
2149
|
-
...(keyFormat !== undefined
|
|
2345
|
+
...(keyFormat !== undefined && {
|
|
2150
2346
|
keyFormat
|
|
2151
|
-
}
|
|
2152
|
-
...(targetPublicKey !== undefined
|
|
2347
|
+
}),
|
|
2348
|
+
...(targetPublicKey !== undefined && {
|
|
2153
2349
|
targetPublicKey
|
|
2154
|
-
}
|
|
2155
|
-
...(stampWith !== undefined
|
|
2350
|
+
}),
|
|
2351
|
+
...(stampWith !== undefined && {
|
|
2156
2352
|
stampWith
|
|
2157
|
-
}
|
|
2353
|
+
}),
|
|
2354
|
+
...(organizationId !== undefined && {
|
|
2355
|
+
organizationId
|
|
2356
|
+
}),
|
|
2357
|
+
onSuccess: () => resolve(),
|
|
2358
|
+
onError: error => reject(error)
|
|
2158
2359
|
})
|
|
2159
|
-
});
|
|
2160
|
-
}, [pushPage]);
|
|
2360
|
+
}));
|
|
2361
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2161
2362
|
const handleExportWalletAccount = react.useCallback(async params => {
|
|
2162
2363
|
const {
|
|
2163
2364
|
address,
|
|
2164
2365
|
targetPublicKey,
|
|
2165
2366
|
keyFormat,
|
|
2166
|
-
stampWith
|
|
2367
|
+
stampWith,
|
|
2368
|
+
organizationId
|
|
2167
2369
|
} = params;
|
|
2168
|
-
pushPage({
|
|
2370
|
+
return new Promise((resolve, reject) => pushPage({
|
|
2169
2371
|
key: "Export wallet account",
|
|
2170
2372
|
content: jsxRuntime.jsx(Export.ExportComponent, {
|
|
2171
2373
|
target: address,
|
|
2172
2374
|
exportType: base.ExportType.WalletAccount,
|
|
2173
|
-
...(keyFormat !== undefined
|
|
2375
|
+
...(keyFormat !== undefined && {
|
|
2174
2376
|
keyFormat
|
|
2175
|
-
}
|
|
2176
|
-
...(targetPublicKey !== undefined
|
|
2377
|
+
}),
|
|
2378
|
+
...(targetPublicKey !== undefined && {
|
|
2177
2379
|
targetPublicKey
|
|
2178
|
-
}
|
|
2179
|
-
...(stampWith !== undefined
|
|
2380
|
+
}),
|
|
2381
|
+
...(stampWith !== undefined && {
|
|
2180
2382
|
stampWith
|
|
2181
|
-
}
|
|
2383
|
+
}),
|
|
2384
|
+
...(organizationId !== undefined && {
|
|
2385
|
+
organizationId
|
|
2386
|
+
}),
|
|
2387
|
+
onSuccess: () => resolve(),
|
|
2388
|
+
onError: error => reject(error)
|
|
2182
2389
|
})
|
|
2183
|
-
});
|
|
2184
|
-
}, [pushPage]);
|
|
2390
|
+
}));
|
|
2391
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2185
2392
|
const handleImportWallet = react.useCallback(async params => {
|
|
2186
2393
|
const {
|
|
2187
2394
|
defaultWalletAccounts,
|
|
2188
2395
|
successPageDuration = 2000,
|
|
2189
|
-
stampWith
|
|
2396
|
+
stampWith,
|
|
2397
|
+
walletName,
|
|
2398
|
+
organizationId,
|
|
2399
|
+
userId
|
|
2190
2400
|
} = params || {};
|
|
2191
2401
|
try {
|
|
2192
2402
|
return utils.withTurnkeyErrorHandling(() => new Promise((resolve, reject) => pushPage({
|
|
@@ -2205,22 +2415,33 @@ const ClientProvider = ({
|
|
|
2205
2415
|
}),
|
|
2206
2416
|
...(stampWith !== undefined && {
|
|
2207
2417
|
stampWith
|
|
2418
|
+
}),
|
|
2419
|
+
...(walletName !== undefined && {
|
|
2420
|
+
name: walletName
|
|
2421
|
+
}),
|
|
2422
|
+
...(organizationId !== undefined && {
|
|
2423
|
+
organizationId
|
|
2424
|
+
}),
|
|
2425
|
+
...(userId !== undefined && {
|
|
2426
|
+
userId
|
|
2208
2427
|
})
|
|
2209
2428
|
})
|
|
2210
|
-
})));
|
|
2429
|
+
})), () => logout());
|
|
2211
2430
|
} catch (error) {
|
|
2212
2431
|
if (error instanceof sdkTypes.TurnkeyError) {
|
|
2213
2432
|
throw error;
|
|
2214
2433
|
}
|
|
2215
2434
|
throw new sdkTypes.TurnkeyError("Failed to import wallet.", sdkTypes.TurnkeyErrorCodes.IMPORT_WALLET_ERROR, error);
|
|
2216
2435
|
}
|
|
2217
|
-
}, [pushPage]);
|
|
2436
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2218
2437
|
const handleImportPrivateKey = react.useCallback(async params => {
|
|
2219
2438
|
const {
|
|
2220
2439
|
curve,
|
|
2221
2440
|
addressFormats,
|
|
2222
2441
|
successPageDuration = 2000,
|
|
2223
|
-
stampWith
|
|
2442
|
+
stampWith,
|
|
2443
|
+
keyName,
|
|
2444
|
+
organizationId
|
|
2224
2445
|
} = params || {};
|
|
2225
2446
|
try {
|
|
2226
2447
|
return utils.withTurnkeyErrorHandling(() => new Promise((resolve, reject) => pushPage({
|
|
@@ -2238,16 +2459,22 @@ const ClientProvider = ({
|
|
|
2238
2459
|
}),
|
|
2239
2460
|
...(stampWith !== undefined && {
|
|
2240
2461
|
stampWith
|
|
2462
|
+
}),
|
|
2463
|
+
...(keyName !== undefined && {
|
|
2464
|
+
name: keyName
|
|
2465
|
+
}),
|
|
2466
|
+
...(organizationId !== undefined && {
|
|
2467
|
+
organizationId
|
|
2241
2468
|
})
|
|
2242
2469
|
})
|
|
2243
|
-
})));
|
|
2470
|
+
})), () => logout());
|
|
2244
2471
|
} catch (error) {
|
|
2245
2472
|
if (error instanceof sdkTypes.TurnkeyError) {
|
|
2246
2473
|
throw error;
|
|
2247
2474
|
}
|
|
2248
2475
|
throw new sdkTypes.TurnkeyError("Failed to import private key.", sdkTypes.TurnkeyErrorCodes.IMPORT_WALLET_ERROR, error);
|
|
2249
2476
|
}
|
|
2250
|
-
}, [pushPage]);
|
|
2477
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2251
2478
|
const handleUpdateUserName = react.useCallback(async params => {
|
|
2252
2479
|
const {
|
|
2253
2480
|
successPageDuration = 2000,
|
|
@@ -2256,8 +2483,14 @@ const ClientProvider = ({
|
|
|
2256
2483
|
stampWith
|
|
2257
2484
|
} = params || {};
|
|
2258
2485
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2259
|
-
|
|
2260
|
-
|
|
2486
|
+
const s = await getSession();
|
|
2487
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
2488
|
+
if (!organizationId) {
|
|
2489
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2490
|
+
}
|
|
2491
|
+
const userId = params?.userId || user?.userId;
|
|
2492
|
+
if (!userId) {
|
|
2493
|
+
throw new sdkTypes.TurnkeyError("A user ID is required to update a user name.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2261
2494
|
}
|
|
2262
2495
|
const onSuccess = () => {
|
|
2263
2496
|
if (!successPageDuration) return;
|
|
@@ -2288,21 +2521,26 @@ const ClientProvider = ({
|
|
|
2288
2521
|
},
|
|
2289
2522
|
successPageDuration: successPageDuration,
|
|
2290
2523
|
stampWith: stampWith,
|
|
2291
|
-
...(title !== undefined
|
|
2524
|
+
...(title !== undefined && {
|
|
2292
2525
|
title
|
|
2293
|
-
}
|
|
2294
|
-
...(subTitle !== undefined
|
|
2526
|
+
}),
|
|
2527
|
+
...(subTitle !== undefined && {
|
|
2295
2528
|
subTitle
|
|
2296
|
-
}
|
|
2529
|
+
}),
|
|
2530
|
+
organizationId: organizationId,
|
|
2531
|
+
userId: userId
|
|
2297
2532
|
}),
|
|
2298
2533
|
showTitle: false
|
|
2299
2534
|
});
|
|
2300
|
-
}));
|
|
2535
|
+
}), () => logout());
|
|
2301
2536
|
} else {
|
|
2302
2537
|
const res = await updateUserName({
|
|
2303
2538
|
userName: params.userName,
|
|
2304
2539
|
userId: user.userId,
|
|
2305
|
-
stampWith
|
|
2540
|
+
stampWith,
|
|
2541
|
+
...(organizationId !== undefined && {
|
|
2542
|
+
organizationId
|
|
2543
|
+
})
|
|
2306
2544
|
});
|
|
2307
2545
|
onSuccess();
|
|
2308
2546
|
return res;
|
|
@@ -2313,23 +2551,30 @@ const ClientProvider = ({
|
|
|
2313
2551
|
}
|
|
2314
2552
|
throw new sdkTypes.TurnkeyError("Failed to update user name.", sdkTypes.TurnkeyErrorCodes.UPDATE_USER_NAME_ERROR, error);
|
|
2315
2553
|
}
|
|
2316
|
-
}, [pushPage]);
|
|
2554
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2317
2555
|
const handleUpdateUserPhoneNumber = react.useCallback(async params => {
|
|
2318
2556
|
const {
|
|
2319
2557
|
successPageDuration = 2000,
|
|
2320
2558
|
subTitle,
|
|
2321
|
-
title
|
|
2559
|
+
title,
|
|
2560
|
+
stampWith
|
|
2322
2561
|
} = params || {};
|
|
2323
2562
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2324
|
-
if (!session) {
|
|
2325
|
-
throw new sdkTypes.TurnkeyError("No active session found.", sdkTypes.TurnkeyErrorCodes.NO_SESSION_FOUND);
|
|
2326
|
-
}
|
|
2327
2563
|
if (!masterConfig) {
|
|
2328
2564
|
throw new sdkTypes.TurnkeyError("Config is not ready yet!", sdkTypes.TurnkeyErrorCodes.CONFIG_NOT_INITIALIZED);
|
|
2329
2565
|
}
|
|
2330
2566
|
if (!masterConfig.auth?.methods?.smsOtpAuthEnabled) {
|
|
2331
2567
|
throw new sdkTypes.TurnkeyError("SMS OTP authentication is not enabled in the configuration.", sdkTypes.TurnkeyErrorCodes.AUTH_METHOD_NOT_ENABLED);
|
|
2332
2568
|
}
|
|
2569
|
+
const s = await getSession();
|
|
2570
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
2571
|
+
if (!organizationId) {
|
|
2572
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2573
|
+
}
|
|
2574
|
+
const userId = params?.userId || s?.userId;
|
|
2575
|
+
if (!userId) {
|
|
2576
|
+
throw new sdkTypes.TurnkeyError("A user ID is required to update a phone number.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2577
|
+
}
|
|
2333
2578
|
const onSuccess = () => {
|
|
2334
2579
|
if (!successPageDuration) return;
|
|
2335
2580
|
pushPage({
|
|
@@ -2354,16 +2599,21 @@ const ClientProvider = ({
|
|
|
2354
2599
|
successPageDuration: successPageDuration,
|
|
2355
2600
|
onSuccess: userId => resolve(userId),
|
|
2356
2601
|
onError: error => reject(error),
|
|
2357
|
-
|
|
2602
|
+
organizationId: organizationId,
|
|
2603
|
+
userId: userId,
|
|
2604
|
+
...(title !== undefined && {
|
|
2358
2605
|
title
|
|
2359
|
-
}
|
|
2360
|
-
...(subTitle !== undefined
|
|
2606
|
+
}),
|
|
2607
|
+
...(subTitle !== undefined && {
|
|
2361
2608
|
subTitle
|
|
2362
|
-
}
|
|
2609
|
+
}),
|
|
2610
|
+
...(stampWith !== undefined && {
|
|
2611
|
+
stampWith
|
|
2612
|
+
})
|
|
2363
2613
|
}),
|
|
2364
2614
|
showTitle: false
|
|
2365
2615
|
});
|
|
2366
|
-
}));
|
|
2616
|
+
}), () => logout());
|
|
2367
2617
|
} else {
|
|
2368
2618
|
const otpId = await initOtp({
|
|
2369
2619
|
otpType: core.OtpType.Sms,
|
|
@@ -2376,6 +2626,8 @@ const ClientProvider = ({
|
|
|
2376
2626
|
otpType: core.OtpType.Sms,
|
|
2377
2627
|
contact: params.phoneNumber,
|
|
2378
2628
|
otpId: otpId,
|
|
2629
|
+
otpLength: masterConfig.auth?.otpLength !== undefined ? Number(masterConfig.auth.otpLength) : undefined,
|
|
2630
|
+
alphanumeric: masterConfig.auth?.otpAlphanumeric,
|
|
2379
2631
|
onContinue: async otpCode => {
|
|
2380
2632
|
try {
|
|
2381
2633
|
const {
|
|
@@ -2389,7 +2641,11 @@ const ClientProvider = ({
|
|
|
2389
2641
|
const res = await updateUserPhoneNumber({
|
|
2390
2642
|
phoneNumber: params.phoneNumber,
|
|
2391
2643
|
verificationToken,
|
|
2392
|
-
userId
|
|
2644
|
+
userId,
|
|
2645
|
+
organizationId,
|
|
2646
|
+
...(stampWith !== undefined && {
|
|
2647
|
+
stampWith
|
|
2648
|
+
})
|
|
2393
2649
|
});
|
|
2394
2650
|
onSuccess();
|
|
2395
2651
|
resolve(res);
|
|
@@ -2409,7 +2665,7 @@ const ClientProvider = ({
|
|
|
2409
2665
|
}),
|
|
2410
2666
|
showTitle: false
|
|
2411
2667
|
});
|
|
2412
|
-
}), callbacks, "Failed to update phone number");
|
|
2668
|
+
}), () => logout(), callbacks, "Failed to update phone number");
|
|
2413
2669
|
}
|
|
2414
2670
|
} catch (error) {
|
|
2415
2671
|
if (error instanceof sdkTypes.TurnkeyError) {
|
|
@@ -2417,16 +2673,23 @@ const ClientProvider = ({
|
|
|
2417
2673
|
}
|
|
2418
2674
|
throw new sdkTypes.TurnkeyError("Failed to initialize OTP for sms verification.", sdkTypes.TurnkeyErrorCodes.INIT_OTP_ERROR, error);
|
|
2419
2675
|
}
|
|
2420
|
-
}, [pushPage]);
|
|
2676
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2421
2677
|
const handleUpdateUserEmail = react.useCallback(async params => {
|
|
2422
2678
|
const {
|
|
2423
2679
|
successPageDuration = 2000,
|
|
2424
2680
|
subTitle,
|
|
2425
|
-
title
|
|
2681
|
+
title,
|
|
2682
|
+
stampWith
|
|
2426
2683
|
} = params || {};
|
|
2427
2684
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2428
|
-
|
|
2429
|
-
|
|
2685
|
+
const s = await getSession();
|
|
2686
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
2687
|
+
if (!organizationId) {
|
|
2688
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2689
|
+
}
|
|
2690
|
+
const userId = params?.userId || s?.userId;
|
|
2691
|
+
if (!userId) {
|
|
2692
|
+
throw new sdkTypes.TurnkeyError("A user ID is required to update an email.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2430
2693
|
}
|
|
2431
2694
|
const onSuccess = () => {
|
|
2432
2695
|
if (!successPageDuration) return;
|
|
@@ -2454,16 +2717,21 @@ const ClientProvider = ({
|
|
|
2454
2717
|
resolve(userId);
|
|
2455
2718
|
},
|
|
2456
2719
|
onError: error => reject(error),
|
|
2457
|
-
|
|
2720
|
+
organizationId: organizationId,
|
|
2721
|
+
userId: userId,
|
|
2722
|
+
...(title !== undefined && {
|
|
2458
2723
|
title
|
|
2459
|
-
}
|
|
2460
|
-
...(subTitle !== undefined
|
|
2724
|
+
}),
|
|
2725
|
+
...(subTitle !== undefined && {
|
|
2461
2726
|
subTitle
|
|
2462
|
-
}
|
|
2727
|
+
}),
|
|
2728
|
+
...(stampWith !== undefined && {
|
|
2729
|
+
stampWith
|
|
2730
|
+
})
|
|
2463
2731
|
}),
|
|
2464
2732
|
showTitle: false
|
|
2465
2733
|
});
|
|
2466
|
-
}));
|
|
2734
|
+
}), () => logout());
|
|
2467
2735
|
} else {
|
|
2468
2736
|
const otpId = await initOtp({
|
|
2469
2737
|
otpType: core.OtpType.Email,
|
|
@@ -2476,6 +2744,8 @@ const ClientProvider = ({
|
|
|
2476
2744
|
otpType: core.OtpType.Email,
|
|
2477
2745
|
contact: params.email,
|
|
2478
2746
|
otpId: otpId,
|
|
2747
|
+
otpLength: masterConfig?.auth?.otpLength !== undefined ? Number(masterConfig.auth.otpLength) : undefined,
|
|
2748
|
+
alphanumeric: masterConfig?.auth?.otpAlphanumeric,
|
|
2479
2749
|
onContinue: async otpCode => {
|
|
2480
2750
|
try {
|
|
2481
2751
|
const {
|
|
@@ -2489,7 +2759,11 @@ const ClientProvider = ({
|
|
|
2489
2759
|
const res = await updateUserEmail({
|
|
2490
2760
|
email: params.email,
|
|
2491
2761
|
verificationToken,
|
|
2492
|
-
userId
|
|
2762
|
+
userId,
|
|
2763
|
+
organizationId,
|
|
2764
|
+
...(stampWith !== undefined && {
|
|
2765
|
+
stampWith
|
|
2766
|
+
})
|
|
2493
2767
|
});
|
|
2494
2768
|
onSuccess();
|
|
2495
2769
|
resolve(res);
|
|
@@ -2506,7 +2780,7 @@ const ClientProvider = ({
|
|
|
2506
2780
|
}),
|
|
2507
2781
|
showTitle: false
|
|
2508
2782
|
});
|
|
2509
|
-
}), callbacks, "Failed to update email");
|
|
2783
|
+
}), () => logout(), callbacks, "Failed to update email");
|
|
2510
2784
|
}
|
|
2511
2785
|
} catch (error) {
|
|
2512
2786
|
if (error instanceof sdkTypes.TurnkeyError) {
|
|
@@ -2514,16 +2788,25 @@ const ClientProvider = ({
|
|
|
2514
2788
|
}
|
|
2515
2789
|
throw new sdkTypes.TurnkeyError("Failed to initialize OTP for email verification.", sdkTypes.TurnkeyErrorCodes.INIT_OTP_ERROR, error);
|
|
2516
2790
|
}
|
|
2517
|
-
}, [pushPage]);
|
|
2791
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2518
2792
|
const handleAddEmail = react.useCallback(async params => {
|
|
2519
2793
|
const {
|
|
2520
2794
|
successPageDuration = 2000,
|
|
2521
2795
|
subTitle,
|
|
2522
|
-
title
|
|
2796
|
+
title,
|
|
2797
|
+
stampWith
|
|
2523
2798
|
} = params || {};
|
|
2524
|
-
if (!client)
|
|
2525
|
-
|
|
2526
|
-
|
|
2799
|
+
if (!client) {
|
|
2800
|
+
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2801
|
+
}
|
|
2802
|
+
const s = await getSession();
|
|
2803
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
2804
|
+
if (!organizationId) {
|
|
2805
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2806
|
+
}
|
|
2807
|
+
const userId = params?.userId || s?.userId;
|
|
2808
|
+
if (!userId) {
|
|
2809
|
+
throw new sdkTypes.TurnkeyError("A user ID is required to add an email.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2527
2810
|
}
|
|
2528
2811
|
const onSuccess = () => {
|
|
2529
2812
|
if (!successPageDuration) return;
|
|
@@ -2556,11 +2839,14 @@ const ClientProvider = ({
|
|
|
2556
2839
|
} : {}),
|
|
2557
2840
|
...(subTitle !== undefined ? {
|
|
2558
2841
|
subTitle
|
|
2559
|
-
} : {})
|
|
2842
|
+
} : {}),
|
|
2843
|
+
organizationId: organizationId,
|
|
2844
|
+
userId: userId,
|
|
2845
|
+
stampWith: stampWith
|
|
2560
2846
|
}),
|
|
2561
2847
|
showTitle: false
|
|
2562
2848
|
});
|
|
2563
|
-
}));
|
|
2849
|
+
}), () => logout());
|
|
2564
2850
|
} else {
|
|
2565
2851
|
const otpId = await initOtp({
|
|
2566
2852
|
otpType: core.OtpType.Email,
|
|
@@ -2573,6 +2859,8 @@ const ClientProvider = ({
|
|
|
2573
2859
|
otpType: core.OtpType.Email,
|
|
2574
2860
|
contact: params.email,
|
|
2575
2861
|
otpId: otpId,
|
|
2862
|
+
otpLength: masterConfig?.auth?.otpLength !== undefined ? Number(masterConfig.auth.otpLength) : undefined,
|
|
2863
|
+
alphanumeric: masterConfig?.auth?.otpAlphanumeric,
|
|
2576
2864
|
onContinue: async otpCode => {
|
|
2577
2865
|
try {
|
|
2578
2866
|
const {
|
|
@@ -2586,7 +2874,9 @@ const ClientProvider = ({
|
|
|
2586
2874
|
const res = await updateUserEmail({
|
|
2587
2875
|
email: params.email,
|
|
2588
2876
|
verificationToken,
|
|
2589
|
-
userId
|
|
2877
|
+
userId,
|
|
2878
|
+
organizationId,
|
|
2879
|
+
stampWith
|
|
2590
2880
|
});
|
|
2591
2881
|
onSuccess();
|
|
2592
2882
|
resolve(res);
|
|
@@ -2603,7 +2893,7 @@ const ClientProvider = ({
|
|
|
2603
2893
|
}),
|
|
2604
2894
|
showTitle: false
|
|
2605
2895
|
});
|
|
2606
|
-
}), callbacks, "Failed to add email");
|
|
2896
|
+
}), () => logout(), callbacks, "Failed to add email");
|
|
2607
2897
|
}
|
|
2608
2898
|
} catch (error) {
|
|
2609
2899
|
if (error instanceof sdkTypes.TurnkeyError) {
|
|
@@ -2611,23 +2901,30 @@ const ClientProvider = ({
|
|
|
2611
2901
|
}
|
|
2612
2902
|
throw new sdkTypes.TurnkeyError("Failed to initialize OTP for email verification.", sdkTypes.TurnkeyErrorCodes.INIT_OTP_ERROR, error);
|
|
2613
2903
|
}
|
|
2614
|
-
}, [pushPage]);
|
|
2904
|
+
}, [pushPage, client, session, user]);
|
|
2615
2905
|
const handleAddPhoneNumber = react.useCallback(async params => {
|
|
2616
2906
|
const {
|
|
2617
2907
|
successPageDuration = 2000,
|
|
2618
2908
|
subTitle,
|
|
2619
|
-
title
|
|
2909
|
+
title,
|
|
2910
|
+
stampWith
|
|
2620
2911
|
} = params || {};
|
|
2621
2912
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2622
|
-
if (!session) {
|
|
2623
|
-
throw new sdkTypes.TurnkeyError("No active session found.", sdkTypes.TurnkeyErrorCodes.NO_SESSION_FOUND);
|
|
2624
|
-
}
|
|
2625
2913
|
if (!masterConfig) {
|
|
2626
2914
|
throw new sdkTypes.TurnkeyError("Config is not ready yet!", sdkTypes.TurnkeyErrorCodes.CONFIG_NOT_INITIALIZED);
|
|
2627
2915
|
}
|
|
2628
2916
|
if (!masterConfig.auth?.methods?.smsOtpAuthEnabled) {
|
|
2629
2917
|
throw new sdkTypes.TurnkeyError("SMS OTP authentication is not enabled in the configuration.", sdkTypes.TurnkeyErrorCodes.AUTH_METHOD_NOT_ENABLED);
|
|
2630
2918
|
}
|
|
2919
|
+
const s = await getSession();
|
|
2920
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
2921
|
+
if (!organizationId) {
|
|
2922
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2923
|
+
}
|
|
2924
|
+
const userId = params?.userId || s?.userId;
|
|
2925
|
+
if (!userId) {
|
|
2926
|
+
throw new sdkTypes.TurnkeyError("A user ID is required to add a phone number.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2927
|
+
}
|
|
2631
2928
|
const onSuccess = () => {
|
|
2632
2929
|
if (!successPageDuration) return;
|
|
2633
2930
|
pushPage({
|
|
@@ -2661,11 +2958,14 @@ const ClientProvider = ({
|
|
|
2661
2958
|
}),
|
|
2662
2959
|
...(subTitle !== undefined && {
|
|
2663
2960
|
subTitle
|
|
2664
|
-
})
|
|
2961
|
+
}),
|
|
2962
|
+
organizationId: organizationId,
|
|
2963
|
+
userId: userId,
|
|
2964
|
+
stampWith: stampWith
|
|
2665
2965
|
}),
|
|
2666
2966
|
showTitle: false
|
|
2667
2967
|
});
|
|
2668
|
-
}), callbacks, "Failed to add phone number");
|
|
2968
|
+
}), () => logout(), callbacks, "Failed to add phone number");
|
|
2669
2969
|
} else {
|
|
2670
2970
|
const otpId = await initOtp({
|
|
2671
2971
|
otpType: core.OtpType.Sms,
|
|
@@ -2678,6 +2978,8 @@ const ClientProvider = ({
|
|
|
2678
2978
|
otpType: core.OtpType.Sms,
|
|
2679
2979
|
contact: params.phoneNumber,
|
|
2680
2980
|
otpId: otpId,
|
|
2981
|
+
otpLength: masterConfig.auth?.otpLength !== undefined ? Number(masterConfig.auth.otpLength) : undefined,
|
|
2982
|
+
alphanumeric: masterConfig?.auth?.otpAlphanumeric,
|
|
2681
2983
|
onContinue: async otpCode => {
|
|
2682
2984
|
try {
|
|
2683
2985
|
const {
|
|
@@ -2691,7 +2993,9 @@ const ClientProvider = ({
|
|
|
2691
2993
|
const res = await updateUserPhoneNumber({
|
|
2692
2994
|
phoneNumber: params.phoneNumber,
|
|
2693
2995
|
verificationToken,
|
|
2694
|
-
userId: user.userId
|
|
2996
|
+
userId: user.userId,
|
|
2997
|
+
organizationId,
|
|
2998
|
+
stampWith
|
|
2695
2999
|
});
|
|
2696
3000
|
onSuccess();
|
|
2697
3001
|
resolve(res);
|
|
@@ -2711,7 +3015,7 @@ const ClientProvider = ({
|
|
|
2711
3015
|
}),
|
|
2712
3016
|
showTitle: false
|
|
2713
3017
|
});
|
|
2714
|
-
}), callbacks, "Failed to add phone number");
|
|
3018
|
+
}), () => logout(), callbacks, "Failed to add phone number");
|
|
2715
3019
|
}
|
|
2716
3020
|
} catch (error) {
|
|
2717
3021
|
if (error instanceof sdkTypes.TurnkeyError) {
|
|
@@ -2719,7 +3023,7 @@ const ClientProvider = ({
|
|
|
2719
3023
|
}
|
|
2720
3024
|
throw new sdkTypes.TurnkeyError("Failed to initialize OTP for sms verification.", sdkTypes.TurnkeyErrorCodes.INIT_OTP_ERROR, error);
|
|
2721
3025
|
}
|
|
2722
|
-
}, [pushPage]);
|
|
3026
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2723
3027
|
const handleRemovePasskey = react.useCallback(async params => {
|
|
2724
3028
|
const {
|
|
2725
3029
|
authenticatorId,
|
|
@@ -2730,8 +3034,10 @@ const ClientProvider = ({
|
|
|
2730
3034
|
userId
|
|
2731
3035
|
} = params;
|
|
2732
3036
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2733
|
-
|
|
2734
|
-
|
|
3037
|
+
const s = await getSession();
|
|
3038
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
3039
|
+
if (!organizationId) {
|
|
3040
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2735
3041
|
}
|
|
2736
3042
|
return utils.withTurnkeyErrorHandling(() => new Promise((resolve, reject) => {
|
|
2737
3043
|
pushPage({
|
|
@@ -2754,13 +3060,16 @@ const ClientProvider = ({
|
|
|
2754
3060
|
}),
|
|
2755
3061
|
...(subTitle !== undefined && {
|
|
2756
3062
|
subTitle
|
|
3063
|
+
}),
|
|
3064
|
+
...(organizationId !== undefined && {
|
|
3065
|
+
organizationId
|
|
2757
3066
|
})
|
|
2758
3067
|
}),
|
|
2759
3068
|
showTitle: false,
|
|
2760
3069
|
preventBack: true
|
|
2761
3070
|
});
|
|
2762
|
-
}), callbacks, "Failed to remove passkey");
|
|
2763
|
-
}, [pushPage]);
|
|
3071
|
+
}), () => logout(), callbacks, "Failed to remove passkey");
|
|
3072
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2764
3073
|
const handleAddPasskey = react.useCallback(async params => {
|
|
2765
3074
|
const {
|
|
2766
3075
|
name,
|
|
@@ -2769,10 +3078,15 @@ const ClientProvider = ({
|
|
|
2769
3078
|
stampWith
|
|
2770
3079
|
} = params || {};
|
|
2771
3080
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2772
|
-
|
|
2773
|
-
|
|
3081
|
+
const s = await getSession();
|
|
3082
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
3083
|
+
if (!organizationId) {
|
|
3084
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
3085
|
+
}
|
|
3086
|
+
const userId = params?.userId || s?.userId;
|
|
3087
|
+
if (!userId) {
|
|
3088
|
+
throw new sdkTypes.TurnkeyError("A user ID or a valid session is required to add a passkey.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2774
3089
|
}
|
|
2775
|
-
const userId = params?.userId || session.userId;
|
|
2776
3090
|
try {
|
|
2777
3091
|
const resPromise = addPasskey({
|
|
2778
3092
|
...(name && {
|
|
@@ -2782,7 +3096,10 @@ const ClientProvider = ({
|
|
|
2782
3096
|
displayName
|
|
2783
3097
|
}),
|
|
2784
3098
|
userId,
|
|
2785
|
-
stampWith
|
|
3099
|
+
stampWith,
|
|
3100
|
+
...(organizationId && {
|
|
3101
|
+
organizationId
|
|
3102
|
+
})
|
|
2786
3103
|
});
|
|
2787
3104
|
resPromise.then(() => {
|
|
2788
3105
|
pushPage({
|
|
@@ -2805,7 +3122,7 @@ const ClientProvider = ({
|
|
|
2805
3122
|
}
|
|
2806
3123
|
throw new sdkTypes.TurnkeyError("Failed to add passkey in handler.", sdkTypes.TurnkeyErrorCodes.ADD_PASSKEY_ERROR, error);
|
|
2807
3124
|
}
|
|
2808
|
-
}, [pushPage]);
|
|
3125
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2809
3126
|
const handleRemoveOauthProvider = react.useCallback(async params => {
|
|
2810
3127
|
const {
|
|
2811
3128
|
providerId,
|
|
@@ -2815,8 +3132,10 @@ const ClientProvider = ({
|
|
|
2815
3132
|
stampWith
|
|
2816
3133
|
} = params;
|
|
2817
3134
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2818
|
-
|
|
2819
|
-
|
|
3135
|
+
const s = await getSession();
|
|
3136
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
3137
|
+
if (!organizationId) {
|
|
3138
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2820
3139
|
}
|
|
2821
3140
|
try {
|
|
2822
3141
|
return new Promise((resolve, reject) => {
|
|
@@ -2837,6 +3156,9 @@ const ClientProvider = ({
|
|
|
2837
3156
|
}),
|
|
2838
3157
|
...(subTitle !== undefined && {
|
|
2839
3158
|
subTitle
|
|
3159
|
+
}),
|
|
3160
|
+
...(organizationId !== undefined && {
|
|
3161
|
+
organizationId
|
|
2840
3162
|
})
|
|
2841
3163
|
}),
|
|
2842
3164
|
showTitle: false,
|
|
@@ -2849,110 +3171,128 @@ const ClientProvider = ({
|
|
|
2849
3171
|
}
|
|
2850
3172
|
throw new sdkTypes.TurnkeyError("Failed to remove OAuth provider in handler.", sdkTypes.TurnkeyErrorCodes.REMOVE_OAUTH_PROVIDER_ERROR, error);
|
|
2851
3173
|
}
|
|
2852
|
-
}, [pushPage]);
|
|
3174
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2853
3175
|
const handleAddOauthProvider = react.useCallback(async params => {
|
|
2854
3176
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2855
|
-
if (!session) {
|
|
2856
|
-
throw new sdkTypes.TurnkeyError("No active session found.", sdkTypes.TurnkeyErrorCodes.NO_SESSION_FOUND);
|
|
2857
|
-
}
|
|
2858
3177
|
const {
|
|
2859
3178
|
providerName,
|
|
2860
|
-
stampWith
|
|
3179
|
+
stampWith,
|
|
3180
|
+
successPageDuration = 2000
|
|
2861
3181
|
} = params;
|
|
2862
|
-
const
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
};
|
|
2881
|
-
switch (providerName) {
|
|
2882
|
-
case sdkTypes.OAuthProviders.DISCORD:
|
|
2883
|
-
{
|
|
2884
|
-
await handleDiscordOauth({
|
|
2885
|
-
openInPage: false,
|
|
2886
|
-
onOauthSuccess
|
|
2887
|
-
});
|
|
2888
|
-
break;
|
|
2889
|
-
}
|
|
2890
|
-
case sdkTypes.OAuthProviders.X:
|
|
2891
|
-
{
|
|
2892
|
-
await handleXOauth({
|
|
2893
|
-
openInPage: false,
|
|
2894
|
-
onOauthSuccess
|
|
2895
|
-
});
|
|
2896
|
-
break;
|
|
2897
|
-
}
|
|
2898
|
-
case sdkTypes.OAuthProviders.GOOGLE:
|
|
2899
|
-
{
|
|
2900
|
-
await handleGoogleOauth({
|
|
2901
|
-
openInPage: false,
|
|
2902
|
-
onOauthSuccess
|
|
2903
|
-
});
|
|
2904
|
-
break;
|
|
2905
|
-
}
|
|
2906
|
-
case sdkTypes.OAuthProviders.APPLE:
|
|
2907
|
-
{
|
|
2908
|
-
await handleAppleOauth({
|
|
2909
|
-
openInPage: false,
|
|
2910
|
-
onOauthSuccess
|
|
3182
|
+
const s = await getSession();
|
|
3183
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
3184
|
+
if (!organizationId) {
|
|
3185
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
3186
|
+
}
|
|
3187
|
+
const userId = params?.userId || s?.userId;
|
|
3188
|
+
if (!userId) {
|
|
3189
|
+
throw new sdkTypes.TurnkeyError("A user ID is required to add an OAuth provider.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
3190
|
+
}
|
|
3191
|
+
return new Promise(async (resolve, reject) => {
|
|
3192
|
+
try {
|
|
3193
|
+
const onOauthSuccess = async params => {
|
|
3194
|
+
await addOauthProvider({
|
|
3195
|
+
providerName: params.providerName,
|
|
3196
|
+
oidcToken: params.oidcToken,
|
|
3197
|
+
stampWith,
|
|
3198
|
+
organizationId,
|
|
3199
|
+
userId
|
|
2911
3200
|
});
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
3201
|
+
resolve();
|
|
3202
|
+
pushPage({
|
|
3203
|
+
key: "OAuth Provider Added",
|
|
3204
|
+
content: jsxRuntime.jsx(Success.SuccessPage, {
|
|
3205
|
+
text: `Successfully added ${params.providerName} OAuth provider!`,
|
|
3206
|
+
duration: successPageDuration,
|
|
3207
|
+
onComplete: () => {
|
|
3208
|
+
closeModal();
|
|
3209
|
+
}
|
|
3210
|
+
}),
|
|
3211
|
+
preventBack: true,
|
|
3212
|
+
showTitle: false
|
|
2919
3213
|
});
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
3214
|
+
};
|
|
3215
|
+
switch (providerName) {
|
|
3216
|
+
case sdkTypes.OAuthProviders.DISCORD:
|
|
3217
|
+
{
|
|
3218
|
+
return await handleDiscordOauth({
|
|
3219
|
+
openInPage: false,
|
|
3220
|
+
onOauthSuccess
|
|
3221
|
+
});
|
|
3222
|
+
}
|
|
3223
|
+
case sdkTypes.OAuthProviders.X:
|
|
3224
|
+
{
|
|
3225
|
+
return await handleXOauth({
|
|
3226
|
+
openInPage: false,
|
|
3227
|
+
onOauthSuccess
|
|
3228
|
+
});
|
|
3229
|
+
}
|
|
3230
|
+
case sdkTypes.OAuthProviders.GOOGLE:
|
|
3231
|
+
{
|
|
3232
|
+
return await handleGoogleOauth({
|
|
3233
|
+
openInPage: false,
|
|
3234
|
+
onOauthSuccess
|
|
3235
|
+
});
|
|
3236
|
+
}
|
|
3237
|
+
case sdkTypes.OAuthProviders.APPLE:
|
|
3238
|
+
{
|
|
3239
|
+
return await handleAppleOauth({
|
|
3240
|
+
openInPage: false,
|
|
3241
|
+
onOauthSuccess
|
|
3242
|
+
});
|
|
3243
|
+
}
|
|
3244
|
+
case sdkTypes.OAuthProviders.FACEBOOK:
|
|
3245
|
+
{
|
|
3246
|
+
return await handleFacebookOauth({
|
|
3247
|
+
openInPage: false,
|
|
3248
|
+
onOauthSuccess
|
|
3249
|
+
});
|
|
3250
|
+
}
|
|
3251
|
+
default:
|
|
3252
|
+
{
|
|
3253
|
+
throw new sdkTypes.TurnkeyError(`Unsupported OAuth provider: ${providerName}`, sdkTypes.TurnkeyErrorCodes.NOT_FOUND);
|
|
3254
|
+
}
|
|
2925
3255
|
}
|
|
2926
|
-
|
|
2927
|
-
|
|
3256
|
+
} catch (error) {
|
|
3257
|
+
reject(error);
|
|
3258
|
+
}
|
|
3259
|
+
});
|
|
3260
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2928
3261
|
const handleConnectExternalWallet = react.useCallback(async params => {
|
|
2929
3262
|
const {
|
|
2930
3263
|
successPageDuration = 2000
|
|
2931
3264
|
} = params || {};
|
|
2932
3265
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2933
|
-
if (!session) {
|
|
2934
|
-
throw new sdkTypes.TurnkeyError("No active session found.", sdkTypes.TurnkeyErrorCodes.NO_SESSION_FOUND);
|
|
2935
|
-
}
|
|
2936
3266
|
if (!masterConfig?.walletConfig?.features?.connecting) {
|
|
2937
3267
|
throw new sdkTypes.TurnkeyError("Wallet connecting is not enabled.", sdkTypes.TurnkeyErrorCodes.FEATURE_NOT_ENABLED);
|
|
2938
3268
|
}
|
|
2939
|
-
const providers = await
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
3269
|
+
const providers = await fetchWalletProviders();
|
|
3270
|
+
return new Promise((resolve, reject) => {
|
|
3271
|
+
pushPage({
|
|
3272
|
+
key: "Connect wallet",
|
|
3273
|
+
content: jsxRuntime.jsx(ConnectWallet.ConnectWalletModal, {
|
|
3274
|
+
providers: providers,
|
|
3275
|
+
successPageDuration: successPageDuration,
|
|
3276
|
+
onSuccess: () => {
|
|
3277
|
+
resolve();
|
|
3278
|
+
},
|
|
3279
|
+
onError: error => {
|
|
3280
|
+
reject(error);
|
|
3281
|
+
}
|
|
3282
|
+
})
|
|
3283
|
+
});
|
|
2946
3284
|
});
|
|
2947
|
-
}, [pushPage]);
|
|
3285
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2948
3286
|
const handleRemoveUserEmail = react.useCallback(async params => {
|
|
2949
3287
|
const {
|
|
2950
3288
|
successPageDuration = 2000,
|
|
2951
3289
|
stampWith,
|
|
2952
3290
|
userId
|
|
2953
3291
|
} = params || {};
|
|
2954
|
-
|
|
2955
|
-
|
|
3292
|
+
const s = await getSession();
|
|
3293
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
3294
|
+
if (!organizationId) {
|
|
3295
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2956
3296
|
}
|
|
2957
3297
|
try {
|
|
2958
3298
|
return new Promise((resolve, reject) => {
|
|
@@ -2971,7 +3311,10 @@ const ClientProvider = ({
|
|
|
2971
3311
|
},
|
|
2972
3312
|
onError: error => {
|
|
2973
3313
|
reject(error);
|
|
2974
|
-
}
|
|
3314
|
+
},
|
|
3315
|
+
...(organizationId !== undefined && {
|
|
3316
|
+
organizationId
|
|
3317
|
+
})
|
|
2975
3318
|
}),
|
|
2976
3319
|
showTitle: false,
|
|
2977
3320
|
preventBack: true
|
|
@@ -2983,15 +3326,17 @@ const ClientProvider = ({
|
|
|
2983
3326
|
}
|
|
2984
3327
|
throw new sdkTypes.TurnkeyError("Failed to remove user email.", sdkTypes.TurnkeyErrorCodes.UPDATE_USER_EMAIL_ERROR, error);
|
|
2985
3328
|
}
|
|
2986
|
-
}, [pushPage]);
|
|
3329
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
2987
3330
|
const handleRemoveUserPhoneNumber = react.useCallback(async params => {
|
|
2988
3331
|
const {
|
|
2989
3332
|
successPageDuration = 2000,
|
|
2990
3333
|
stampWith,
|
|
2991
3334
|
userId
|
|
2992
3335
|
} = params || {};
|
|
2993
|
-
|
|
2994
|
-
|
|
3336
|
+
const s = await getSession();
|
|
3337
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
3338
|
+
if (!organizationId) {
|
|
3339
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2995
3340
|
}
|
|
2996
3341
|
try {
|
|
2997
3342
|
return new Promise((resolve, reject) => {
|
|
@@ -3010,7 +3355,10 @@ const ClientProvider = ({
|
|
|
3010
3355
|
},
|
|
3011
3356
|
onError: error => {
|
|
3012
3357
|
reject(error);
|
|
3013
|
-
}
|
|
3358
|
+
},
|
|
3359
|
+
...(organizationId !== undefined && {
|
|
3360
|
+
organizationId
|
|
3361
|
+
})
|
|
3014
3362
|
}),
|
|
3015
3363
|
showTitle: false,
|
|
3016
3364
|
preventBack: true
|
|
@@ -3022,7 +3370,7 @@ const ClientProvider = ({
|
|
|
3022
3370
|
}
|
|
3023
3371
|
throw new sdkTypes.TurnkeyError("Failed to remove user phone number.", sdkTypes.TurnkeyErrorCodes.UPDATE_USER_PHONE_NUMBER_ERROR, error);
|
|
3024
3372
|
}
|
|
3025
|
-
}, [pushPage]);
|
|
3373
|
+
}, [pushPage, masterConfig, client, session, user]);
|
|
3026
3374
|
react.useEffect(() => {
|
|
3027
3375
|
if (proxyAuthConfigRef.current) return;
|
|
3028
3376
|
// Only fetch the proxy auth config once. Use that to build the master config.
|
|
@@ -3059,23 +3407,29 @@ const ClientProvider = ({
|
|
|
3059
3407
|
* only trigger `refreshWallets()` once.
|
|
3060
3408
|
*
|
|
3061
3409
|
* Defining the debounced function outside of the `useEffect` ensures all event
|
|
3062
|
-
* listeners in `
|
|
3410
|
+
* listeners in `initializeWalletProviderListeners` share the same instance, instead of creating
|
|
3063
3411
|
* a new one on every render.
|
|
3064
3412
|
*/
|
|
3065
3413
|
const debouncedRefreshWallets = utils.useDebouncedCallback(refreshWallets, 100);
|
|
3414
|
+
const debouncedFetchWalletProviders = utils.useDebouncedCallback(fetchWalletProviders, 100);
|
|
3066
3415
|
react.useEffect(() => {
|
|
3067
3416
|
if (!client) return;
|
|
3068
|
-
const
|
|
3417
|
+
const handleUpdateState = async () => {
|
|
3069
3418
|
// we only refresh the wallets if there is an active session
|
|
3070
3419
|
// this is needed because a disconnect event can occur
|
|
3071
3420
|
// while the user is unauthenticated
|
|
3421
|
+
//
|
|
3422
|
+
// WalletProviders state is updated regardless of session state
|
|
3072
3423
|
if (session) {
|
|
3073
|
-
// this
|
|
3424
|
+
// this updates both the wallets and walletProviders state
|
|
3074
3425
|
await debouncedRefreshWallets();
|
|
3426
|
+
} else {
|
|
3427
|
+
// this updates only the walletProviders state
|
|
3428
|
+
await debouncedFetchWalletProviders();
|
|
3075
3429
|
}
|
|
3076
3430
|
};
|
|
3077
3431
|
let cleanup = () => {};
|
|
3078
|
-
initializeWalletProviderListeners(walletProviders,
|
|
3432
|
+
initializeWalletProviderListeners(walletProviders, handleUpdateState).then(fn => {
|
|
3079
3433
|
cleanup = fn;
|
|
3080
3434
|
}).catch(err => {
|
|
3081
3435
|
console.error("Failed to init providers:", err);
|
|
@@ -3083,7 +3437,7 @@ const ClientProvider = ({
|
|
|
3083
3437
|
return () => {
|
|
3084
3438
|
cleanup();
|
|
3085
3439
|
};
|
|
3086
|
-
}, [client, walletProviders]);
|
|
3440
|
+
}, [client, walletProviders, session]);
|
|
3087
3441
|
react.useEffect(() => {
|
|
3088
3442
|
// authState must be consistent with session state. We found during testing that there are cases where the session and authState can be out of sync in very rare edge cases.
|
|
3089
3443
|
// This will ensure that they are always in sync and remove the need to setAuthState manually in other places.
|
|
@@ -3098,6 +3452,11 @@ const ClientProvider = ({
|
|
|
3098
3452
|
if (!client || !masterConfig) return;
|
|
3099
3453
|
completeRedirectOauth().finally(() => {
|
|
3100
3454
|
clearSessionTimeouts();
|
|
3455
|
+
// if auth or wallet connecting features are enabled, we want to fetch
|
|
3456
|
+
// the wallet providers to set the state
|
|
3457
|
+
if (masterConfig.walletConfig?.features?.auth || masterConfig.walletConfig?.features?.connecting) {
|
|
3458
|
+
fetchWalletProviders();
|
|
3459
|
+
}
|
|
3101
3460
|
initializeSessions().finally(() => {
|
|
3102
3461
|
// Set the client state to ready only after all initializations are done.
|
|
3103
3462
|
setClientState(base.ClientState.Ready);
|
|
@@ -3115,13 +3474,14 @@ const ClientProvider = ({
|
|
|
3115
3474
|
authState,
|
|
3116
3475
|
user,
|
|
3117
3476
|
wallets,
|
|
3477
|
+
walletProviders,
|
|
3118
3478
|
config: masterConfig,
|
|
3119
3479
|
httpClient: client?.httpClient,
|
|
3120
3480
|
createPasskey,
|
|
3121
3481
|
logout,
|
|
3122
3482
|
loginWithPasskey,
|
|
3123
3483
|
signUpWithPasskey,
|
|
3124
|
-
|
|
3484
|
+
fetchWalletProviders,
|
|
3125
3485
|
connectWalletAccount,
|
|
3126
3486
|
disconnectWalletAccount,
|
|
3127
3487
|
switchWalletAccountChain,
|
|
@@ -3144,6 +3504,8 @@ const ClientProvider = ({
|
|
|
3144
3504
|
signTransaction,
|
|
3145
3505
|
signAndSendTransaction,
|
|
3146
3506
|
fetchUser,
|
|
3507
|
+
fetchOrCreateP256ApiKeyUser,
|
|
3508
|
+
fetchOrCreatePolicies,
|
|
3147
3509
|
refreshUser,
|
|
3148
3510
|
updateUserEmail,
|
|
3149
3511
|
removeUserEmail,
|