@turnkey/react-wallet-kit 1.0.0 → 1.1.1
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/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.js.map +1 -1
- package/dist/components/auth/Email.mjs +13 -14
- package/dist/components/auth/Email.mjs.map +1 -1
- package/dist/components/auth/OAuth.js.map +1 -1
- 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.js.map +1 -1
- 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.map +1 -1
- package/dist/components/auth/Wallet.js +89 -49
- package/dist/components/auth/Wallet.js.map +1 -1
- package/dist/components/auth/Wallet.mjs +154 -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.js.map +1 -1
- 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.d.ts.map +1 -1
- package/dist/components/design/Inputs.js +29 -7
- package/dist/components/design/Inputs.js.map +1 -1
- package/dist/components/design/Inputs.mjs +26 -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 +12 -4
- package/dist/components/export/Export.js.map +1 -1
- package/dist/components/export/Export.mjs +35 -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 +17 -9
- package/dist/components/export/ExportWarning.js.map +1 -1
- package/dist/components/export/ExportWarning.mjs +64 -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 +28 -15
- package/dist/components/import/Import.js.map +1 -1
- package/dist/components/import/Import.mjs +122 -112
- 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 +4 -0
- package/dist/components/sign/Message.js.map +1 -1
- package/dist/components/sign/Message.mjs +24 -22
- package/dist/components/sign/Message.mjs.map +1 -1
- package/dist/components/user/ConnectWallet.d.ts +3 -1
- package/dist/components/user/ConnectWallet.d.ts.map +1 -1
- package/dist/components/user/ConnectWallet.js +53 -30
- package/dist/components/user/ConnectWallet.js.map +1 -1
- package/dist/components/user/ConnectWallet.mjs +85 -36
- 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 +6 -2
- package/dist/components/user/RemovePasskey.js.map +1 -1
- package/dist/components/user/RemovePasskey.mjs +26 -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 +15 -2
- 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 +658 -308
- package/dist/providers/client/Provider.js.map +1 -1
- package/dist/providers/client/Provider.mjs +2527 -2111
- package/dist/providers/client/Provider.mjs.map +1 -1
- package/dist/providers/client/Types.d.ts +130 -183
- 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 +4 -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 +84 -3
- package/dist/providers/modal/Root.js.map +1 -1
- package/dist/providers/modal/Root.mjs +103 -16
- 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/typedoc-entry/index.d.ts +4 -0
- package/dist/typedoc-entry/index.d.ts.map +1 -0
- package/dist/types/base.d.ts +8 -1
- 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 +2 -1
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +21 -6
- package/dist/utils/utils.js.map +1 -1
- package/dist/utils/utils.mjs +103 -91
- package/dist/utils/utils.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -136,7 +136,10 @@ const ClientProvider = ({
|
|
|
136
136
|
icon: freeBrandsSvgIcons.faFacebook
|
|
137
137
|
})
|
|
138
138
|
}),
|
|
139
|
-
showTitle: false
|
|
139
|
+
showTitle: false,
|
|
140
|
+
onClose: () => {
|
|
141
|
+
reject(new sdkTypes.TurnkeyError("User cancelled the Facebook authentication process.", sdkTypes.TurnkeyErrorCodes.USER_CANCELED));
|
|
142
|
+
}
|
|
140
143
|
});
|
|
141
144
|
});
|
|
142
145
|
}
|
|
@@ -198,7 +201,10 @@ const ClientProvider = ({
|
|
|
198
201
|
icon: freeBrandsSvgIcons.faDiscord
|
|
199
202
|
})
|
|
200
203
|
}),
|
|
201
|
-
showTitle: false
|
|
204
|
+
showTitle: false,
|
|
205
|
+
onClose: () => {
|
|
206
|
+
reject(new sdkTypes.TurnkeyError("User cancelled the Discord authentication process.", sdkTypes.TurnkeyErrorCodes.USER_CANCELED));
|
|
207
|
+
}
|
|
202
208
|
});
|
|
203
209
|
});
|
|
204
210
|
}
|
|
@@ -253,7 +259,10 @@ const ClientProvider = ({
|
|
|
253
259
|
icon: freeBrandsSvgIcons.faXTwitter
|
|
254
260
|
})
|
|
255
261
|
}),
|
|
256
|
-
showTitle: false
|
|
262
|
+
showTitle: false,
|
|
263
|
+
onClose: () => {
|
|
264
|
+
reject(new sdkTypes.TurnkeyError("User cancelled the Twitter authentication process.", sdkTypes.TurnkeyErrorCodes.USER_CANCELED));
|
|
265
|
+
}
|
|
257
266
|
});
|
|
258
267
|
});
|
|
259
268
|
}
|
|
@@ -314,7 +323,10 @@ const ClientProvider = ({
|
|
|
314
323
|
},
|
|
315
324
|
icon: icon
|
|
316
325
|
}),
|
|
317
|
-
showTitle: false
|
|
326
|
+
showTitle: false,
|
|
327
|
+
onClose: () => {
|
|
328
|
+
reject(new sdkTypes.TurnkeyError(`User cancelled the ${providerName} authentication process.`, sdkTypes.TurnkeyErrorCodes.USER_CANCELED));
|
|
329
|
+
}
|
|
318
330
|
});
|
|
319
331
|
});
|
|
320
332
|
} else if (callbacks?.onOauthRedirect) {
|
|
@@ -362,11 +374,29 @@ const ClientProvider = ({
|
|
|
362
374
|
const oauthOrder = config.auth?.oauthOrder ?? ["google", "apple", "x", "discord", "facebook"].filter(provider => resolvedMethods[`${provider}OauthEnabled`]);
|
|
363
375
|
// Set a default ordering for the overall auth methods
|
|
364
376
|
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);
|
|
377
|
+
// Warn if they are trying to set auth proxy only settings directly
|
|
378
|
+
if (config.auth?.sessionExpirationSeconds) {
|
|
379
|
+
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.");
|
|
380
|
+
}
|
|
381
|
+
if (config.auth?.otpAlphanumeric !== undefined) {
|
|
382
|
+
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.");
|
|
383
|
+
}
|
|
384
|
+
if (config.auth?.otpLength) {
|
|
385
|
+
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.");
|
|
386
|
+
}
|
|
387
|
+
// These are settings that can only be set via the auth proxy config
|
|
388
|
+
const authProxyOnlySettings = {
|
|
389
|
+
sessionExpirationSeconds: proxyAuthConfig?.sessionExpirationSeconds,
|
|
390
|
+
otpAlphanumeric: proxyAuthConfig?.otpAlphanumeric ?? true,
|
|
391
|
+
// This fallback will never be hit. This is purely for the tests to pass before mono is released
|
|
392
|
+
otpLength: proxyAuthConfig?.otpLength ?? "6" // This fallback will never be hit. This is purely for the tests to pass before mono is released
|
|
393
|
+
};
|
|
365
394
|
return {
|
|
366
395
|
...config,
|
|
367
396
|
// Overrides:
|
|
368
397
|
auth: {
|
|
369
398
|
...config.auth,
|
|
399
|
+
...authProxyOnlySettings,
|
|
370
400
|
methods: resolvedMethods,
|
|
371
401
|
oauthConfig: {
|
|
372
402
|
...config.auth?.oauthConfig,
|
|
@@ -376,7 +406,6 @@ const ClientProvider = ({
|
|
|
376
406
|
// (e.g. Safari) block popups
|
|
377
407
|
openOauthInPage: isMobile ? true : config.auth?.oauthConfig?.openOauthInPage
|
|
378
408
|
},
|
|
379
|
-
sessionExpirationSeconds: proxyAuthConfig?.sessionExpirationSeconds,
|
|
380
409
|
methodOrder,
|
|
381
410
|
oauthOrder,
|
|
382
411
|
autoRefreshSession: config.auth?.autoRefreshSession ?? true
|
|
@@ -508,36 +537,47 @@ const ClientProvider = ({
|
|
|
508
537
|
* @internal
|
|
509
538
|
* Attach listeners for connected wallet providers so we can refresh state on changes.
|
|
510
539
|
*
|
|
511
|
-
* - Ethereum: listens for disconnect and chain
|
|
540
|
+
* - Ethereum: listens for disconnect and chain/account changes to trigger a refresh.
|
|
512
541
|
* - Solana: listens for disconnect via Wallet Standard `change` events to trigger a refresh.
|
|
513
|
-
* - WalletConnect:
|
|
542
|
+
* - WalletConnect:
|
|
543
|
+
* - listens for disconnect and other state changes via its unified `change` event
|
|
544
|
+
* - additionally listens for `pairingExpired` events (proposal expiration), in which
|
|
545
|
+
* case we re-fetch providers to refresh the pairing URI for the UI.
|
|
514
546
|
*
|
|
515
547
|
* Notes:
|
|
516
|
-
* - Only providers
|
|
517
|
-
*
|
|
548
|
+
* - Only connected providers are bound, except WalletConnect which must always register
|
|
549
|
+
* to handle proposal expiration even if no active session exists.
|
|
550
|
+
* - Since all WalletConnect providers share the same session, we only attach to one.
|
|
518
551
|
*
|
|
519
552
|
* @param walletProviders - Discovered providers; only connected ones are bound.
|
|
520
|
-
* @param
|
|
553
|
+
* @param onUpdateState - Invoked when a relevant provider event occurs.
|
|
521
554
|
* @returns Cleanup function that removes all listeners registered by this call.
|
|
522
555
|
*/
|
|
523
|
-
async function initializeWalletProviderListeners(walletProviders,
|
|
556
|
+
async function initializeWalletProviderListeners(walletProviders, onUpdateState) {
|
|
524
557
|
if (walletProviders.length === 0) return () => {};
|
|
525
558
|
const cleanups = [];
|
|
526
559
|
// we only want to initialize these listeners for connected walletProviders
|
|
527
560
|
const nativeOnly = provider => provider.interfaceType !== core.WalletInterfaceType.WalletConnect;
|
|
528
561
|
const ethProviders = masterConfig?.walletConfig?.chains.ethereum?.native ? walletProviders.filter(provider => provider.chainInfo.namespace === core.Chain.Ethereum && nativeOnly(provider) && provider.connectedAddresses.length > 0) : [];
|
|
529
562
|
const solProviders = masterConfig?.walletConfig?.chains.solana?.native ? walletProviders.filter(provider => provider.chainInfo.namespace === core.Chain.Solana && nativeOnly(provider) && provider.connectedAddresses.length > 0) : [];
|
|
530
|
-
//
|
|
531
|
-
//
|
|
532
|
-
//
|
|
533
|
-
|
|
534
|
-
|
|
563
|
+
// WalletConnect is excluded from native event wiring. Instead,
|
|
564
|
+
// it uses a unified `change` event exposed by our custom wrapper
|
|
565
|
+
//
|
|
566
|
+
// unlike native providers, we register listeners for WalletConnect
|
|
567
|
+
// even if it’s not currently “connected”. This is required so we
|
|
568
|
+
// can detect proposal expiration events and display the new regenerated
|
|
569
|
+
// URI for the UI
|
|
570
|
+
const wcProviders = walletProviders.filter(p => p.interfaceType === core.WalletInterfaceType.WalletConnect);
|
|
571
|
+
// since all WalletConnect providers share the same underlying session
|
|
572
|
+
// and emit identical events, we only attach listeners to a single provider
|
|
573
|
+
const wcProvider = wcProviders.find(p => p.interfaceType === core.WalletInterfaceType.WalletConnect);
|
|
574
|
+
function attachEthereumListeners(provider, onUpdateState) {
|
|
535
575
|
if (typeof provider.on !== "function") return;
|
|
536
|
-
const handleChainChanged = _chainId =>
|
|
537
|
-
const handleAccountsChanged = accounts => {
|
|
538
|
-
if (accounts.length === 0)
|
|
576
|
+
const handleChainChanged = async _chainId => onUpdateState();
|
|
577
|
+
const handleAccountsChanged = async accounts => {
|
|
578
|
+
if (accounts.length === 0) onUpdateState();
|
|
539
579
|
};
|
|
540
|
-
const handleDisconnect = () =>
|
|
580
|
+
const handleDisconnect = () => onUpdateState();
|
|
541
581
|
provider.on("chainChanged", handleChainChanged);
|
|
542
582
|
provider.on("accountsChanged", handleAccountsChanged);
|
|
543
583
|
provider.on("disconnect", handleDisconnect);
|
|
@@ -547,32 +587,43 @@ const ClientProvider = ({
|
|
|
547
587
|
provider.removeListener("disconnect", handleDisconnect);
|
|
548
588
|
};
|
|
549
589
|
}
|
|
550
|
-
function attachSolanaListeners(provider,
|
|
590
|
+
function attachSolanaListeners(provider, onUpdateState) {
|
|
551
591
|
const cleanups = [];
|
|
552
592
|
const walletEvents = provider?.features?.["standard:events"];
|
|
553
593
|
if (walletEvents?.on) {
|
|
554
|
-
const offChange = walletEvents.on("change", _evt => {
|
|
555
|
-
|
|
594
|
+
const offChange = walletEvents.on("change", async _evt => {
|
|
595
|
+
await onUpdateState();
|
|
556
596
|
});
|
|
557
597
|
cleanups.push(offChange);
|
|
558
598
|
}
|
|
559
599
|
return () => cleanups.forEach(fn => fn());
|
|
560
600
|
}
|
|
561
601
|
ethProviders.forEach(p => {
|
|
562
|
-
const cleanup = attachEthereumListeners(p.provider,
|
|
602
|
+
const cleanup = attachEthereumListeners(p.provider, onUpdateState);
|
|
563
603
|
if (cleanup) cleanups.push(cleanup);
|
|
564
604
|
});
|
|
565
605
|
solProviders.forEach(p => {
|
|
566
|
-
const cleanup = attachSolanaListeners(p.provider,
|
|
606
|
+
const cleanup = attachSolanaListeners(p.provider, onUpdateState);
|
|
567
607
|
if (cleanup) cleanups.push(cleanup);
|
|
568
608
|
});
|
|
569
|
-
|
|
570
|
-
const standardEvents =
|
|
609
|
+
if (wcProvider) {
|
|
610
|
+
const standardEvents = wcProvider.provider?.features?.["standard:events"];
|
|
571
611
|
if (standardEvents?.on) {
|
|
572
|
-
|
|
573
|
-
|
|
612
|
+
if (standardEvents?.on) {
|
|
613
|
+
const unsubscribe = standardEvents.on("change", async evt => {
|
|
614
|
+
// if the event is a proposalExpired, we want to re-fetch the providers
|
|
615
|
+
// to refresh the uri, there is no need to refresh the wallets state
|
|
616
|
+
if (evt?.type === "pairingExpired") {
|
|
617
|
+
debouncedFetchWalletProviders();
|
|
618
|
+
}
|
|
619
|
+
// any other event (disconnect, chain switch, accounts changed)
|
|
620
|
+
// we refresh the wallets state
|
|
621
|
+
await onUpdateState();
|
|
622
|
+
});
|
|
623
|
+
cleanups.push(unsubscribe);
|
|
624
|
+
}
|
|
574
625
|
}
|
|
575
|
-
}
|
|
626
|
+
}
|
|
576
627
|
return () => {
|
|
577
628
|
cleanups.forEach(remove => remove());
|
|
578
629
|
};
|
|
@@ -782,7 +833,7 @@ const ClientProvider = ({
|
|
|
782
833
|
}
|
|
783
834
|
return utils.withTurnkeyErrorHandling(() => client.createPasskey({
|
|
784
835
|
...params
|
|
785
|
-
}), callbacks, "Failed to create passkey");
|
|
836
|
+
}), () => logout(), callbacks, "Failed to create passkey");
|
|
786
837
|
}, [client, callbacks]);
|
|
787
838
|
const logout = react.useCallback(async params => {
|
|
788
839
|
if (!client) {
|
|
@@ -795,7 +846,7 @@ const ClientProvider = ({
|
|
|
795
846
|
await client.logout(params);
|
|
796
847
|
// We only handle post logout if the sessionKey is defined since that means we actually logged out of a session.
|
|
797
848
|
if (sessionKey) handlePostLogout(sessionKey);
|
|
798
|
-
}, callbacks, "Failed to logout");
|
|
849
|
+
}, () => logout(), callbacks, "Failed to logout");
|
|
799
850
|
return;
|
|
800
851
|
}, [client, callbacks]);
|
|
801
852
|
const loginWithPasskey = react.useCallback(async params => {
|
|
@@ -806,7 +857,7 @@ const ClientProvider = ({
|
|
|
806
857
|
const res = await utils.withTurnkeyErrorHandling(() => client.loginWithPasskey({
|
|
807
858
|
...params,
|
|
808
859
|
expirationSeconds
|
|
809
|
-
}), callbacks, "Failed to login with passkey");
|
|
860
|
+
}), () => logout(), callbacks, "Failed to login with passkey");
|
|
810
861
|
if (res) {
|
|
811
862
|
await handlePostAuth({
|
|
812
863
|
method: base.AuthMethod.Passkey,
|
|
@@ -845,7 +896,7 @@ const ClientProvider = ({
|
|
|
845
896
|
...params,
|
|
846
897
|
passkeyDisplayName: passkeyName,
|
|
847
898
|
expirationSeconds
|
|
848
|
-
}), callbacks, "Failed to sign up with passkey");
|
|
899
|
+
}), () => logout(), callbacks, "Failed to sign up with passkey");
|
|
849
900
|
if (res) {
|
|
850
901
|
await handlePostAuth({
|
|
851
902
|
method: base.AuthMethod.Passkey,
|
|
@@ -871,26 +922,34 @@ const ClientProvider = ({
|
|
|
871
922
|
if (!client) {
|
|
872
923
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
873
924
|
}
|
|
874
|
-
await client.connectWalletAccount(walletProvider);
|
|
875
|
-
|
|
876
|
-
await
|
|
925
|
+
const address = await client.connectWalletAccount(walletProvider);
|
|
926
|
+
let wallets;
|
|
927
|
+
const s = await getSession();
|
|
928
|
+
if (s) {
|
|
929
|
+
// this will update our walletProvider state
|
|
930
|
+
wallets = await refreshWallets();
|
|
931
|
+
} else {
|
|
932
|
+
wallets = await fetchWallets({
|
|
933
|
+
connectedOnly: true
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
// we narrow to only connected wallets
|
|
937
|
+
// because we know the account must come from one of them
|
|
938
|
+
const connectedWallets = wallets.filter(w => w.source === core.WalletSource.Connected);
|
|
939
|
+
// find the matching account
|
|
940
|
+
const matchedAccount = connectedWallets.flatMap(w => w.accounts).find(a => a.address === address);
|
|
941
|
+
if (!matchedAccount) {
|
|
942
|
+
throw new sdkTypes.TurnkeyError(`No connected wallet account found for address: ${address}`, sdkTypes.TurnkeyErrorCodes.NO_WALLET_FOUND);
|
|
943
|
+
}
|
|
944
|
+
return matchedAccount;
|
|
877
945
|
}, [client, callbacks]);
|
|
878
946
|
const disconnectWalletAccount = react.useCallback(async walletProvider => {
|
|
879
947
|
if (!client) {
|
|
880
948
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
881
949
|
}
|
|
882
950
|
await client.disconnectWalletAccount(walletProvider);
|
|
883
|
-
//
|
|
884
|
-
//
|
|
885
|
-
// you can disconnect a wallet before actually being logged in
|
|
886
|
-
//
|
|
887
|
-
// 2. it was a WalletConnect provider that we just disconnected. Since
|
|
888
|
-
// native providers emit a disconnect event which will already refresh
|
|
889
|
-
// the wallets. This event is triggered in `initializeWalletProviderListeners()`
|
|
890
|
-
if (session && walletProvider.interfaceType === core.WalletInterfaceType.WalletConnect) {
|
|
891
|
-
// this will update our walletProvider state
|
|
892
|
-
await refreshWallets();
|
|
893
|
-
}
|
|
951
|
+
// no need here to call `refreshWallets()` because the provider emits a disconnect event which
|
|
952
|
+
// will trigger a refresh via the listener we set up in `initializeWalletProviderListeners()`
|
|
894
953
|
}, [client, callbacks]);
|
|
895
954
|
const switchWalletAccountChain = react.useCallback(async params => {
|
|
896
955
|
if (!client) {
|
|
@@ -909,7 +968,7 @@ const ClientProvider = ({
|
|
|
909
968
|
const res = await utils.withTurnkeyErrorHandling(() => client.loginWithWallet({
|
|
910
969
|
...params,
|
|
911
970
|
expirationSeconds
|
|
912
|
-
}), callbacks, "Failed to login with wallet");
|
|
971
|
+
}), () => logout(), callbacks, "Failed to login with wallet");
|
|
913
972
|
if (res) {
|
|
914
973
|
await handlePostAuth({
|
|
915
974
|
method: base.AuthMethod.Wallet,
|
|
@@ -938,7 +997,7 @@ const ClientProvider = ({
|
|
|
938
997
|
const res = await utils.withTurnkeyErrorHandling(() => client.signUpWithWallet({
|
|
939
998
|
...params,
|
|
940
999
|
expirationSeconds
|
|
941
|
-
}), callbacks, "Failed to sign up with wallet");
|
|
1000
|
+
}), () => logout(), callbacks, "Failed to sign up with wallet");
|
|
942
1001
|
if (res) {
|
|
943
1002
|
await handlePostAuth({
|
|
944
1003
|
method: base.AuthMethod.Wallet,
|
|
@@ -967,7 +1026,7 @@ const ClientProvider = ({
|
|
|
967
1026
|
const res = await utils.withTurnkeyErrorHandling(() => client.loginOrSignupWithWallet({
|
|
968
1027
|
...params,
|
|
969
1028
|
expirationSeconds
|
|
970
|
-
}), callbacks, "Failed to login or sign up with wallet");
|
|
1029
|
+
}), () => logout(), callbacks, "Failed to login or sign up with wallet");
|
|
971
1030
|
if (res) {
|
|
972
1031
|
await handlePostAuth({
|
|
973
1032
|
method: base.AuthMethod.Wallet,
|
|
@@ -981,19 +1040,19 @@ const ClientProvider = ({
|
|
|
981
1040
|
if (!client) {
|
|
982
1041
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
983
1042
|
}
|
|
984
|
-
return utils.withTurnkeyErrorHandling(() => client.initOtp(params), callbacks, "Failed to initialize OTP");
|
|
1043
|
+
return utils.withTurnkeyErrorHandling(() => client.initOtp(params), () => logout(), callbacks, "Failed to initialize OTP");
|
|
985
1044
|
}, [client, callbacks]);
|
|
986
1045
|
const verifyOtp = react.useCallback(async params => {
|
|
987
1046
|
if (!client) {
|
|
988
1047
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
989
1048
|
}
|
|
990
|
-
return utils.withTurnkeyErrorHandling(() => client.verifyOtp(params), callbacks, "Failed to verify OTP");
|
|
1049
|
+
return utils.withTurnkeyErrorHandling(() => client.verifyOtp(params), () => logout(), callbacks, "Failed to verify OTP");
|
|
991
1050
|
}, [client, callbacks]);
|
|
992
1051
|
const loginWithOtp = react.useCallback(async params => {
|
|
993
1052
|
if (!client) {
|
|
994
1053
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
995
1054
|
}
|
|
996
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.loginWithOtp(params), callbacks, "Failed to login with OTP");
|
|
1055
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.loginWithOtp(params), () => logout(), callbacks, "Failed to login with OTP");
|
|
997
1056
|
if (res) {
|
|
998
1057
|
await handlePostAuth({
|
|
999
1058
|
method: base.AuthMethod.Otp,
|
|
@@ -1025,7 +1084,7 @@ const ClientProvider = ({
|
|
|
1025
1084
|
} : {
|
|
1026
1085
|
...params
|
|
1027
1086
|
};
|
|
1028
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.signUpWithOtp(params), callbacks, "Failed to sign up with OTP");
|
|
1087
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.signUpWithOtp(params), () => logout(), callbacks, "Failed to sign up with OTP");
|
|
1029
1088
|
if (res) {
|
|
1030
1089
|
await handlePostAuth({
|
|
1031
1090
|
method: base.AuthMethod.Otp,
|
|
@@ -1057,7 +1116,7 @@ const ClientProvider = ({
|
|
|
1057
1116
|
} : {
|
|
1058
1117
|
...params
|
|
1059
1118
|
};
|
|
1060
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.completeOtp(params), callbacks, "Failed to complete OTP");
|
|
1119
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.completeOtp(params), () => logout(), callbacks, "Failed to complete OTP");
|
|
1061
1120
|
if (res) {
|
|
1062
1121
|
await handlePostAuth({
|
|
1063
1122
|
method: base.AuthMethod.Otp,
|
|
@@ -1071,7 +1130,7 @@ const ClientProvider = ({
|
|
|
1071
1130
|
if (!client) {
|
|
1072
1131
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1073
1132
|
}
|
|
1074
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.loginWithOauth(params), callbacks, "Failed to login with OAuth");
|
|
1133
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.loginWithOauth(params), () => logout(), callbacks, "Failed to login with OAuth");
|
|
1075
1134
|
if (res) {
|
|
1076
1135
|
await handlePostAuth({
|
|
1077
1136
|
method: base.AuthMethod.Oauth,
|
|
@@ -1096,7 +1155,7 @@ const ClientProvider = ({
|
|
|
1096
1155
|
} : {
|
|
1097
1156
|
...params
|
|
1098
1157
|
};
|
|
1099
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.signUpWithOauth(params), callbacks, "Failed to sign up with OAuth");
|
|
1158
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.signUpWithOauth(params), () => logout(), callbacks, "Failed to sign up with OAuth");
|
|
1100
1159
|
if (res) {
|
|
1101
1160
|
await handlePostAuth({
|
|
1102
1161
|
method: base.AuthMethod.Oauth,
|
|
@@ -1121,7 +1180,7 @@ const ClientProvider = ({
|
|
|
1121
1180
|
} : {
|
|
1122
1181
|
...params
|
|
1123
1182
|
};
|
|
1124
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.completeOauth(params), callbacks, "Failed to complete OAuth");
|
|
1183
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.completeOauth(params), () => logout(), callbacks, "Failed to complete OAuth");
|
|
1125
1184
|
if (res) {
|
|
1126
1185
|
await handlePostAuth({
|
|
1127
1186
|
method: base.AuthMethod.Oauth,
|
|
@@ -1135,23 +1194,23 @@ const ClientProvider = ({
|
|
|
1135
1194
|
if (!client) {
|
|
1136
1195
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1137
1196
|
}
|
|
1138
|
-
return utils.withTurnkeyErrorHandling(() => client.fetchWallets(params), callbacks, "Failed to fetch wallets");
|
|
1197
|
+
return utils.withTurnkeyErrorHandling(() => client.fetchWallets(params), () => logout(), callbacks, "Failed to fetch wallets");
|
|
1139
1198
|
}, [client, callbacks]);
|
|
1140
1199
|
const fetchWalletAccounts = react.useCallback(async params => {
|
|
1141
1200
|
if (!client) {
|
|
1142
1201
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1143
1202
|
}
|
|
1144
|
-
return utils.withTurnkeyErrorHandling(() => client.fetchWalletAccounts(params), callbacks, "Failed to fetch wallet accounts");
|
|
1203
|
+
return utils.withTurnkeyErrorHandling(() => client.fetchWalletAccounts(params), () => logout(), callbacks, "Failed to fetch wallet accounts");
|
|
1145
1204
|
}, [client, callbacks]);
|
|
1146
1205
|
const fetchPrivateKeys = react.useCallback(async params => {
|
|
1147
1206
|
if (!client) {
|
|
1148
1207
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1149
1208
|
}
|
|
1150
|
-
return utils.withTurnkeyErrorHandling(() => client.fetchPrivateKeys(params), callbacks, "Failed to fetch private keys");
|
|
1209
|
+
return utils.withTurnkeyErrorHandling(() => client.fetchPrivateKeys(params), () => logout(), callbacks, "Failed to fetch private keys");
|
|
1151
1210
|
}, [client, callbacks]);
|
|
1152
1211
|
const signMessage = react.useCallback(async params => {
|
|
1153
1212
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1154
|
-
return utils.withTurnkeyErrorHandling(() => client.signMessage(params), callbacks, "Failed to sign message");
|
|
1213
|
+
return utils.withTurnkeyErrorHandling(() => client.signMessage(params), () => logout(), callbacks, "Failed to sign message");
|
|
1155
1214
|
}, [client, callbacks]);
|
|
1156
1215
|
const handleSignMessage = react.useCallback(async params => {
|
|
1157
1216
|
const {
|
|
@@ -1181,160 +1240,241 @@ const ClientProvider = ({
|
|
|
1181
1240
|
}),
|
|
1182
1241
|
...(params?.addEthereumPrefix && {
|
|
1183
1242
|
addEthereumPrefix: params.addEthereumPrefix
|
|
1243
|
+
}),
|
|
1244
|
+
...(params?.organizationId && {
|
|
1245
|
+
organizationId: params.organizationId
|
|
1184
1246
|
})
|
|
1185
|
-
})
|
|
1247
|
+
}),
|
|
1248
|
+
onClose: () => reject(new sdkTypes.TurnkeyError("User cancelled the signing process.", sdkTypes.TurnkeyErrorCodes.USER_CANCELED))
|
|
1186
1249
|
});
|
|
1187
1250
|
});
|
|
1188
1251
|
}, [client, callbacks]);
|
|
1189
1252
|
const signTransaction = react.useCallback(async params => {
|
|
1190
1253
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1191
|
-
return utils.withTurnkeyErrorHandling(() => client.signTransaction(params), callbacks, "Failed to sign transaction");
|
|
1254
|
+
return utils.withTurnkeyErrorHandling(() => client.signTransaction(params), () => logout(), callbacks, "Failed to sign transaction");
|
|
1192
1255
|
}, [client, callbacks]);
|
|
1193
1256
|
const signAndSendTransaction = react.useCallback(async params => {
|
|
1194
1257
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1195
|
-
return utils.withTurnkeyErrorHandling(() => client.signAndSendTransaction(params), callbacks, "Failed to sign transaction");
|
|
1258
|
+
return utils.withTurnkeyErrorHandling(() => client.signAndSendTransaction(params), () => logout(), callbacks, "Failed to sign transaction");
|
|
1196
1259
|
}, [client, callbacks]);
|
|
1197
1260
|
const fetchUser = react.useCallback(async params => {
|
|
1198
1261
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1199
|
-
return utils.withTurnkeyErrorHandling(() => client.fetchUser(params), callbacks, "Failed to fetch user");
|
|
1262
|
+
return utils.withTurnkeyErrorHandling(() => client.fetchUser(params), () => logout(), callbacks, "Failed to fetch user");
|
|
1200
1263
|
}, [client, callbacks]);
|
|
1201
1264
|
const fetchOrCreateP256ApiKeyUser = react.useCallback(async params => {
|
|
1202
1265
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1203
|
-
return utils.withTurnkeyErrorHandling(() => client.fetchOrCreateP256ApiKeyUser(params), callbacks, "Failed to fetch or create delegated access user");
|
|
1266
|
+
return utils.withTurnkeyErrorHandling(() => client.fetchOrCreateP256ApiKeyUser(params), () => logout(), callbacks, "Failed to fetch or create delegated access user");
|
|
1204
1267
|
}, [client, callbacks]);
|
|
1205
1268
|
const fetchOrCreatePolicies = react.useCallback(async params => {
|
|
1206
1269
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1207
|
-
return utils.withTurnkeyErrorHandling(() => client.fetchOrCreatePolicies(params), callbacks, "Failed to fetch or create delegated access user");
|
|
1270
|
+
return utils.withTurnkeyErrorHandling(() => client.fetchOrCreatePolicies(params), () => logout(), callbacks, "Failed to fetch or create delegated access user");
|
|
1208
1271
|
}, [client, callbacks]);
|
|
1209
1272
|
const updateUserEmail = react.useCallback(async params => {
|
|
1210
1273
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1211
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.updateUserEmail(params), callbacks, "Failed to update user email");
|
|
1274
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.updateUserEmail(params), () => logout(), callbacks, "Failed to update user email");
|
|
1212
1275
|
if (res) await refreshUser({
|
|
1213
|
-
stampWith: params?.stampWith
|
|
1276
|
+
stampWith: params?.stampWith,
|
|
1277
|
+
...(params?.organizationId && {
|
|
1278
|
+
organizationId: params.organizationId
|
|
1279
|
+
}),
|
|
1280
|
+
...(params?.userId && {
|
|
1281
|
+
userId: params.userId
|
|
1282
|
+
})
|
|
1214
1283
|
});
|
|
1215
1284
|
return res;
|
|
1216
1285
|
}, [client, callbacks]);
|
|
1217
1286
|
const removeUserEmail = react.useCallback(async params => {
|
|
1218
1287
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1219
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.removeUserEmail(params), callbacks, "Failed to remove user email");
|
|
1288
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.removeUserEmail(params), () => logout(), callbacks, "Failed to remove user email");
|
|
1220
1289
|
if (res) await refreshUser({
|
|
1221
|
-
stampWith: params?.stampWith
|
|
1290
|
+
stampWith: params?.stampWith,
|
|
1291
|
+
...(params?.organizationId && {
|
|
1292
|
+
organizationId: params.organizationId
|
|
1293
|
+
}),
|
|
1294
|
+
...(params?.userId && {
|
|
1295
|
+
userId: params.userId
|
|
1296
|
+
})
|
|
1222
1297
|
});
|
|
1223
1298
|
return res;
|
|
1224
1299
|
}, [client, callbacks]);
|
|
1225
1300
|
const updateUserPhoneNumber = react.useCallback(async params => {
|
|
1226
1301
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1227
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.updateUserPhoneNumber(params), callbacks, "Failed to update user phone number");
|
|
1302
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.updateUserPhoneNumber(params), () => logout(), callbacks, "Failed to update user phone number");
|
|
1228
1303
|
if (res) await refreshUser({
|
|
1229
|
-
stampWith: params?.stampWith
|
|
1304
|
+
stampWith: params?.stampWith,
|
|
1305
|
+
...(params?.organizationId && {
|
|
1306
|
+
organizationId: params.organizationId
|
|
1307
|
+
}),
|
|
1308
|
+
...(params?.userId && {
|
|
1309
|
+
userId: params.userId
|
|
1310
|
+
})
|
|
1230
1311
|
});
|
|
1231
1312
|
return res;
|
|
1232
1313
|
}, [client, callbacks]);
|
|
1233
1314
|
const removeUserPhoneNumber = react.useCallback(async params => {
|
|
1234
1315
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1235
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.removeUserPhoneNumber(params), callbacks, "Failed to remove user phone number");
|
|
1316
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.removeUserPhoneNumber(params), () => logout(), callbacks, "Failed to remove user phone number");
|
|
1236
1317
|
if (res) await refreshUser({
|
|
1237
|
-
stampWith: params?.stampWith
|
|
1318
|
+
stampWith: params?.stampWith,
|
|
1319
|
+
...(params?.organizationId && {
|
|
1320
|
+
organizationId: params.organizationId
|
|
1321
|
+
}),
|
|
1322
|
+
...(params?.userId && {
|
|
1323
|
+
userId: params.userId
|
|
1324
|
+
})
|
|
1238
1325
|
});
|
|
1239
1326
|
return res;
|
|
1240
1327
|
}, [client, callbacks]);
|
|
1241
1328
|
const updateUserName = react.useCallback(async params => {
|
|
1242
1329
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1243
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.updateUserName(params), callbacks, "Failed to update user name");
|
|
1330
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.updateUserName(params), () => logout(), callbacks, "Failed to update user name");
|
|
1244
1331
|
if (res) await refreshUser({
|
|
1245
|
-
stampWith: params?.stampWith
|
|
1332
|
+
stampWith: params?.stampWith,
|
|
1333
|
+
...(params?.organizationId && {
|
|
1334
|
+
organizationId: params.organizationId
|
|
1335
|
+
}),
|
|
1336
|
+
...(params?.userId && {
|
|
1337
|
+
userId: params.userId
|
|
1338
|
+
})
|
|
1246
1339
|
});
|
|
1247
1340
|
return res;
|
|
1248
1341
|
}, [client, callbacks]);
|
|
1249
1342
|
const addOauthProvider = react.useCallback(async params => {
|
|
1250
1343
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1251
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.addOauthProvider(params), callbacks, "Failed to add OAuth provider");
|
|
1344
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.addOauthProvider(params), () => logout(), callbacks, "Failed to add OAuth provider");
|
|
1252
1345
|
if (res) await refreshUser({
|
|
1253
|
-
stampWith: params?.stampWith
|
|
1346
|
+
stampWith: params?.stampWith,
|
|
1347
|
+
...(params?.organizationId && {
|
|
1348
|
+
organizationId: params.organizationId
|
|
1349
|
+
}),
|
|
1350
|
+
...(params?.userId && {
|
|
1351
|
+
userId: params.userId
|
|
1352
|
+
})
|
|
1254
1353
|
});
|
|
1255
1354
|
return res;
|
|
1256
1355
|
}, [client, callbacks]);
|
|
1257
1356
|
const removeOauthProviders = react.useCallback(async params => {
|
|
1258
1357
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1259
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.removeOauthProviders(params), callbacks, "Failed to remove OAuth providers");
|
|
1358
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.removeOauthProviders(params), () => logout(), callbacks, "Failed to remove OAuth providers");
|
|
1260
1359
|
if (res) await refreshUser({
|
|
1261
|
-
stampWith: params?.stampWith
|
|
1360
|
+
stampWith: params?.stampWith,
|
|
1361
|
+
...(params?.organizationId && {
|
|
1362
|
+
organizationId: params.organizationId
|
|
1363
|
+
}),
|
|
1364
|
+
...(params?.userId && {
|
|
1365
|
+
userId: params.userId
|
|
1366
|
+
})
|
|
1262
1367
|
});
|
|
1263
1368
|
return res;
|
|
1264
1369
|
}, [client, callbacks]);
|
|
1265
1370
|
const addPasskey = react.useCallback(async params => {
|
|
1266
1371
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1267
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.addPasskey(params), callbacks, "Failed to add passkey");
|
|
1372
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.addPasskey(params), () => logout(), callbacks, "Failed to add passkey");
|
|
1268
1373
|
if (res) await refreshUser({
|
|
1269
|
-
stampWith: params?.stampWith
|
|
1374
|
+
stampWith: params?.stampWith,
|
|
1375
|
+
...(params?.organizationId && {
|
|
1376
|
+
organizationId: params.organizationId
|
|
1377
|
+
}),
|
|
1378
|
+
...(params?.userId && {
|
|
1379
|
+
userId: params.userId
|
|
1380
|
+
})
|
|
1270
1381
|
});
|
|
1271
1382
|
return res;
|
|
1272
1383
|
}, [client, callbacks]);
|
|
1273
1384
|
const removePasskeys = react.useCallback(async params => {
|
|
1274
1385
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1275
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.removePasskeys(params), callbacks, "Failed to remove passkeys");
|
|
1386
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.removePasskeys(params), () => logout(), callbacks, "Failed to remove passkeys");
|
|
1276
1387
|
if (res) await refreshUser({
|
|
1277
|
-
stampWith: params?.stampWith
|
|
1388
|
+
stampWith: params?.stampWith,
|
|
1389
|
+
...(params?.organizationId && {
|
|
1390
|
+
organizationId: params.organizationId
|
|
1391
|
+
}),
|
|
1392
|
+
...(params?.userId && {
|
|
1393
|
+
userId: params.userId
|
|
1394
|
+
})
|
|
1278
1395
|
});
|
|
1279
1396
|
return res;
|
|
1280
1397
|
}, [client, callbacks]);
|
|
1281
1398
|
const createWallet = react.useCallback(async params => {
|
|
1282
1399
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1283
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.createWallet(params), callbacks, "Failed to create wallet");
|
|
1284
|
-
|
|
1285
|
-
|
|
1400
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.createWallet(params), () => logout(), callbacks, "Failed to create wallet");
|
|
1401
|
+
const s = await getSession();
|
|
1402
|
+
if (res && s) await refreshWallets({
|
|
1403
|
+
stampWith: params?.stampWith,
|
|
1404
|
+
...(params?.organizationId && {
|
|
1405
|
+
organizationId: params.organizationId
|
|
1406
|
+
})
|
|
1286
1407
|
});
|
|
1287
1408
|
return res;
|
|
1288
|
-
}, [client, callbacks]);
|
|
1409
|
+
}, [client, session, callbacks]);
|
|
1289
1410
|
const createWalletAccounts = react.useCallback(async params => {
|
|
1290
1411
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1291
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.createWalletAccounts(params), callbacks, "Failed to create wallet accounts");
|
|
1292
|
-
|
|
1293
|
-
|
|
1412
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.createWalletAccounts(params), () => logout(), callbacks, "Failed to create wallet accounts");
|
|
1413
|
+
const s = await getSession();
|
|
1414
|
+
if (res && s) await refreshWallets({
|
|
1415
|
+
stampWith: params?.stampWith,
|
|
1416
|
+
...(params?.organizationId && {
|
|
1417
|
+
organizationId: params.organizationId
|
|
1418
|
+
})
|
|
1294
1419
|
});
|
|
1295
1420
|
return res;
|
|
1296
|
-
}, [client, callbacks]);
|
|
1421
|
+
}, [client, session, callbacks]);
|
|
1297
1422
|
const exportWallet = react.useCallback(async params => {
|
|
1298
1423
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1299
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.exportWallet(params), callbacks, "Failed to export wallet");
|
|
1300
|
-
|
|
1301
|
-
|
|
1424
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.exportWallet(params), () => logout(), callbacks, "Failed to export wallet");
|
|
1425
|
+
const s = await getSession();
|
|
1426
|
+
if (res && s) await refreshWallets({
|
|
1427
|
+
stampWith: params?.stampWith,
|
|
1428
|
+
...(params?.organizationId && {
|
|
1429
|
+
organizationId: params.organizationId
|
|
1430
|
+
})
|
|
1302
1431
|
});
|
|
1303
1432
|
return res;
|
|
1304
|
-
}, [client, callbacks]);
|
|
1433
|
+
}, [client, session, callbacks]);
|
|
1305
1434
|
const exportPrivateKey = react.useCallback(async params => {
|
|
1306
1435
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1307
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.exportPrivateKey(params), callbacks, "Failed to export private key");
|
|
1436
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.exportPrivateKey(params), () => logout(), callbacks, "Failed to export private key");
|
|
1308
1437
|
return res;
|
|
1309
1438
|
}, [client, callbacks]);
|
|
1310
1439
|
const exportWalletAccount = react.useCallback(async params => {
|
|
1311
1440
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1312
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.exportWalletAccount(params), callbacks, "Failed to export wallet accounts");
|
|
1313
|
-
|
|
1314
|
-
|
|
1441
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.exportWalletAccount(params), () => logout(), callbacks, "Failed to export wallet accounts");
|
|
1442
|
+
const s = await getSession();
|
|
1443
|
+
if (res && s) await refreshWallets({
|
|
1444
|
+
stampWith: params?.stampWith,
|
|
1445
|
+
...(params?.organizationId && {
|
|
1446
|
+
organizationId: params.organizationId
|
|
1447
|
+
})
|
|
1315
1448
|
});
|
|
1316
1449
|
return res;
|
|
1317
1450
|
}, [client, callbacks, masterConfig, session, user]);
|
|
1318
1451
|
const importWallet = react.useCallback(async params => {
|
|
1319
1452
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1320
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.importWallet(params), callbacks, "Failed to import wallet");
|
|
1321
|
-
|
|
1322
|
-
|
|
1453
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.importWallet(params), () => logout(), callbacks, "Failed to import wallet");
|
|
1454
|
+
const s = await getSession();
|
|
1455
|
+
if (res && s) await refreshWallets({
|
|
1456
|
+
stampWith: params?.stampWith,
|
|
1457
|
+
...(params?.organizationId && {
|
|
1458
|
+
organizationId: params.organizationId
|
|
1459
|
+
}),
|
|
1460
|
+
...(params?.userId && {
|
|
1461
|
+
userId: params.userId
|
|
1462
|
+
})
|
|
1323
1463
|
});
|
|
1324
1464
|
return res;
|
|
1325
1465
|
}, [client, callbacks, masterConfig, session, user]);
|
|
1326
1466
|
const importPrivateKey = react.useCallback(async params => {
|
|
1327
1467
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1328
|
-
const res = await utils.withTurnkeyErrorHandling(() => client.importPrivateKey(params), callbacks, "Failed to import private key");
|
|
1468
|
+
const res = await utils.withTurnkeyErrorHandling(() => client.importPrivateKey(params), () => logout(), callbacks, "Failed to import private key");
|
|
1329
1469
|
return res;
|
|
1330
1470
|
}, [client, callbacks, masterConfig, session, user]);
|
|
1331
1471
|
const deleteSubOrganization = react.useCallback(async params => {
|
|
1332
1472
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1333
|
-
return utils.withTurnkeyErrorHandling(() => client.deleteSubOrganization(params), callbacks, "Failed to delete sub-organization");
|
|
1473
|
+
return utils.withTurnkeyErrorHandling(() => client.deleteSubOrganization(params), () => logout(), callbacks, "Failed to delete sub-organization");
|
|
1334
1474
|
}, [client, callbacks, masterConfig, session, user]);
|
|
1335
1475
|
const storeSession = react.useCallback(async params => {
|
|
1336
1476
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1337
|
-
await utils.withTurnkeyErrorHandling(() => client.storeSession(params), callbacks, "Failed to store session");
|
|
1477
|
+
await utils.withTurnkeyErrorHandling(() => client.storeSession(params), () => logout(), callbacks, "Failed to store session");
|
|
1338
1478
|
const sessionKey = await getActiveSessionKey();
|
|
1339
1479
|
const session = await getSession({
|
|
1340
1480
|
...(sessionKey && {
|
|
@@ -1352,18 +1492,29 @@ const ClientProvider = ({
|
|
|
1352
1492
|
}, [client, callbacks, masterConfig, session, user]);
|
|
1353
1493
|
const clearSession = react.useCallback(async params => {
|
|
1354
1494
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1355
|
-
await utils.withTurnkeyErrorHandling(() => client.clearSession(params), callbacks, "Failed to clear session");
|
|
1356
|
-
const
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1495
|
+
await utils.withTurnkeyErrorHandling(async () => client.clearSession(params), () => logout(), callbacks, "Failed to clear session");
|
|
1496
|
+
const sessionKey = params?.sessionKey ?? (await getActiveSessionKey());
|
|
1497
|
+
if (!sessionKey) return;
|
|
1498
|
+
if (!params?.sessionKey) {
|
|
1499
|
+
setSession(undefined);
|
|
1500
|
+
}
|
|
1501
|
+
clearSessionTimeouts([sessionKey]);
|
|
1502
|
+
// clear only the cleared session from allSessions
|
|
1503
|
+
const newAllSessions = {
|
|
1504
|
+
...allSessions
|
|
1505
|
+
};
|
|
1506
|
+
if (newAllSessions) {
|
|
1507
|
+
delete newAllSessions[sessionKey];
|
|
1508
|
+
}
|
|
1509
|
+
setAllSessions(newAllSessions);
|
|
1360
1510
|
return;
|
|
1361
1511
|
}, [client, callbacks, session, user, masterConfig]);
|
|
1362
1512
|
const clearAllSessions = react.useCallback(async () => {
|
|
1363
1513
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1364
1514
|
setSession(undefined);
|
|
1365
1515
|
setAllSessions(undefined);
|
|
1366
|
-
|
|
1516
|
+
clearSessionTimeouts();
|
|
1517
|
+
return await utils.withTurnkeyErrorHandling(() => client.clearAllSessions(), () => logout(), callbacks, "Failed to clear all sessions");
|
|
1367
1518
|
}, [client, callbacks, session, user, masterConfig]);
|
|
1368
1519
|
const refreshSession = react.useCallback(async params => {
|
|
1369
1520
|
if (!client) {
|
|
@@ -1376,7 +1527,7 @@ const ClientProvider = ({
|
|
|
1376
1527
|
const sessionKey = params?.sessionKey ?? activeSessionKey;
|
|
1377
1528
|
const res = await utils.withTurnkeyErrorHandling(() => client.refreshSession({
|
|
1378
1529
|
...params
|
|
1379
|
-
}), callbacks, "Failed to refresh session");
|
|
1530
|
+
}), () => logout(), callbacks, "Failed to refresh session");
|
|
1380
1531
|
const session = await getSession({
|
|
1381
1532
|
sessionKey
|
|
1382
1533
|
});
|
|
@@ -1396,71 +1547,89 @@ const ClientProvider = ({
|
|
|
1396
1547
|
}, [client, callbacks, scheduleSessionExpiration, session, user, masterConfig]);
|
|
1397
1548
|
const getSession = react.useCallback(async params => {
|
|
1398
1549
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1399
|
-
return utils.withTurnkeyErrorHandling(() => client.getSession(params), callbacks, "Failed to get session");
|
|
1550
|
+
return utils.withTurnkeyErrorHandling(() => client.getSession(params), () => logout(), callbacks, "Failed to get session");
|
|
1400
1551
|
}, [client, callbacks, masterConfig, session, user]);
|
|
1401
1552
|
const getAllSessions = react.useCallback(async () => {
|
|
1402
1553
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1403
|
-
return utils.withTurnkeyErrorHandling(() => client.getAllSessions(), callbacks, "Failed to get all sessions");
|
|
1554
|
+
return utils.withTurnkeyErrorHandling(() => client.getAllSessions(), () => logout(), callbacks, "Failed to get all sessions");
|
|
1404
1555
|
}, [client, callbacks, masterConfig, session, user]);
|
|
1405
1556
|
const setActiveSession = react.useCallback(async params => {
|
|
1406
1557
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1407
1558
|
const session = await utils.withTurnkeyErrorHandling(() => client.getSession({
|
|
1408
1559
|
sessionKey: params.sessionKey
|
|
1409
|
-
}), callbacks, "Failed to get session");
|
|
1410
|
-
|
|
1560
|
+
}), () => logout(), callbacks, "Failed to get session");
|
|
1561
|
+
const s = await getSession();
|
|
1562
|
+
if (!s) {
|
|
1411
1563
|
throw new sdkTypes.TurnkeyError("Session not found.", sdkTypes.TurnkeyErrorCodes.NOT_FOUND);
|
|
1412
1564
|
}
|
|
1413
|
-
await utils.withTurnkeyErrorHandling(() => client.setActiveSession(params), callbacks, "Failed to set active session");
|
|
1565
|
+
await utils.withTurnkeyErrorHandling(() => client.setActiveSession(params), () => logout(), callbacks, "Failed to set active session");
|
|
1414
1566
|
setSession(session);
|
|
1415
1567
|
await utils.withTurnkeyErrorHandling(async () => {
|
|
1416
1568
|
await refreshWallets();
|
|
1417
1569
|
await refreshUser();
|
|
1418
|
-
}, callbacks, "Failed to refresh data after setting active session");
|
|
1570
|
+
}, () => logout(), callbacks, "Failed to refresh data after setting active session");
|
|
1419
1571
|
return;
|
|
1420
1572
|
}, [client, callbacks, session, user, masterConfig]);
|
|
1421
1573
|
const getActiveSessionKey = react.useCallback(async () => {
|
|
1422
1574
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1423
|
-
return utils.withTurnkeyErrorHandling(() => client.getActiveSessionKey(), callbacks, "Failed to get active session key");
|
|
1575
|
+
return utils.withTurnkeyErrorHandling(() => client.getActiveSessionKey(), () => logout(), callbacks, "Failed to get active session key");
|
|
1424
1576
|
}, [client, callbacks, masterConfig, session, user]);
|
|
1425
1577
|
const clearUnusedKeyPairs = react.useCallback(async () => {
|
|
1426
1578
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1427
|
-
return utils.withTurnkeyErrorHandling(() => client.clearUnusedKeyPairs(), callbacks, "Failed to clear unused key pairs");
|
|
1579
|
+
return utils.withTurnkeyErrorHandling(() => client.clearUnusedKeyPairs(), () => logout(), callbacks, "Failed to clear unused key pairs");
|
|
1428
1580
|
}, [client, callbacks, masterConfig, session, user]);
|
|
1429
1581
|
const createApiKeyPair = react.useCallback(async params => {
|
|
1430
1582
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1431
|
-
return utils.withTurnkeyErrorHandling(() => client.createApiKeyPair(params), callbacks, "Failed to create API key pair");
|
|
1583
|
+
return utils.withTurnkeyErrorHandling(() => client.createApiKeyPair(params), () => logout(), callbacks, "Failed to create API key pair");
|
|
1432
1584
|
}, [client, callbacks, session, user, masterConfig]);
|
|
1433
1585
|
const getProxyAuthConfig = react.useCallback(async () => {
|
|
1434
1586
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1435
|
-
return utils.withTurnkeyErrorHandling(() => client.getProxyAuthConfig(), callbacks, "Failed to get proxy auth config");
|
|
1587
|
+
return utils.withTurnkeyErrorHandling(() => client.getProxyAuthConfig(), () => logout(), callbacks, "Failed to get proxy auth config");
|
|
1436
1588
|
}, [client, callbacks, masterConfig, session, user]);
|
|
1437
1589
|
const refreshUser = react.useCallback(async params => {
|
|
1438
1590
|
if (!masterConfig?.autoRefreshManagedState) return;
|
|
1439
1591
|
const {
|
|
1440
|
-
stampWith
|
|
1592
|
+
stampWith,
|
|
1593
|
+
organizationId,
|
|
1594
|
+
userId
|
|
1441
1595
|
} = params || {};
|
|
1442
1596
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1443
1597
|
const user = await utils.withTurnkeyErrorHandling(() => fetchUser({
|
|
1444
|
-
stampWith
|
|
1445
|
-
|
|
1598
|
+
stampWith,
|
|
1599
|
+
...(organizationId && {
|
|
1600
|
+
organizationId
|
|
1601
|
+
}),
|
|
1602
|
+
...(userId && {
|
|
1603
|
+
userId
|
|
1604
|
+
})
|
|
1605
|
+
}), () => logout(), callbacks, "Failed to refresh user");
|
|
1446
1606
|
if (user) {
|
|
1447
1607
|
setUser(user);
|
|
1448
1608
|
}
|
|
1449
1609
|
}, [client, callbacks, fetchUser, masterConfig, session, user]);
|
|
1450
1610
|
const refreshWallets = react.useCallback(async params => {
|
|
1451
|
-
if (!masterConfig?.autoRefreshManagedState) return;
|
|
1611
|
+
if (!masterConfig?.autoRefreshManagedState) return [];
|
|
1452
1612
|
const {
|
|
1453
|
-
stampWith
|
|
1613
|
+
stampWith,
|
|
1614
|
+
organizationId,
|
|
1615
|
+
userId
|
|
1454
1616
|
} = params || {};
|
|
1455
1617
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
1456
|
-
const walletProviders = await utils.withTurnkeyErrorHandling(() => fetchWalletProviders(), callbacks, "Failed to refresh wallets");
|
|
1618
|
+
const walletProviders = await utils.withTurnkeyErrorHandling(() => fetchWalletProviders(), () => logout(), callbacks, "Failed to refresh wallets");
|
|
1457
1619
|
const wallets = await utils.withTurnkeyErrorHandling(() => fetchWallets({
|
|
1458
1620
|
stampWith,
|
|
1459
|
-
walletProviders
|
|
1460
|
-
|
|
1621
|
+
walletProviders,
|
|
1622
|
+
...(organizationId && {
|
|
1623
|
+
organizationId
|
|
1624
|
+
}),
|
|
1625
|
+
...(userId && {
|
|
1626
|
+
userId
|
|
1627
|
+
})
|
|
1628
|
+
}), () => logout(), callbacks, "Failed to refresh wallets");
|
|
1461
1629
|
if (wallets) {
|
|
1462
1630
|
setWallets(wallets);
|
|
1463
1631
|
}
|
|
1632
|
+
return wallets;
|
|
1464
1633
|
}, [client, callbacks, fetchWalletProviders, fetchWallets, masterConfig, session, user]);
|
|
1465
1634
|
const handleDiscordOauth = react.useCallback(async params => {
|
|
1466
1635
|
const {
|
|
@@ -2135,86 +2304,112 @@ const ClientProvider = ({
|
|
|
2135
2304
|
}
|
|
2136
2305
|
}, [client, callbacks, masterConfig, client, session, user]);
|
|
2137
2306
|
const handleLogin = react.useCallback(async params => {
|
|
2307
|
+
const logo = masterConfig?.ui?.darkMode ? params?.logoDark ?? masterConfig?.ui?.logoDark : params?.logoLight ?? masterConfig?.ui?.logoLight;
|
|
2138
2308
|
pushPage({
|
|
2139
|
-
key: "Log in or sign up",
|
|
2309
|
+
key: params?.title ?? "Log in or sign up",
|
|
2140
2310
|
content: jsxRuntime.jsx(index.AuthComponent, {
|
|
2141
|
-
sessionKey: params?.sessionKey
|
|
2142
|
-
|
|
2311
|
+
sessionKey: params?.sessionKey,
|
|
2312
|
+
logo: logo,
|
|
2313
|
+
logoClassName: params?.logoClassName,
|
|
2314
|
+
title: params?.title
|
|
2315
|
+
}),
|
|
2316
|
+
showTitle: logo ? false : true
|
|
2143
2317
|
});
|
|
2144
2318
|
}, [pushPage, masterConfig, client, session, user]);
|
|
2145
2319
|
const handleExportWallet = react.useCallback(async params => {
|
|
2146
2320
|
const {
|
|
2147
2321
|
walletId,
|
|
2148
2322
|
targetPublicKey,
|
|
2149
|
-
stampWith
|
|
2323
|
+
stampWith,
|
|
2324
|
+
organizationId
|
|
2150
2325
|
} = params;
|
|
2151
|
-
pushPage({
|
|
2326
|
+
return new Promise((resolve, reject) => pushPage({
|
|
2152
2327
|
key: "Export wallet",
|
|
2153
2328
|
content: jsxRuntime.jsx(Export.ExportComponent, {
|
|
2154
2329
|
target: walletId,
|
|
2155
2330
|
exportType: base.ExportType.Wallet,
|
|
2156
|
-
...(targetPublicKey !== undefined
|
|
2331
|
+
...(targetPublicKey !== undefined && {
|
|
2157
2332
|
targetPublicKey
|
|
2158
|
-
}
|
|
2159
|
-
...(stampWith !== undefined
|
|
2333
|
+
}),
|
|
2334
|
+
...(stampWith !== undefined && {
|
|
2160
2335
|
stampWith
|
|
2161
|
-
}
|
|
2336
|
+
}),
|
|
2337
|
+
...(organizationId !== undefined && {
|
|
2338
|
+
organizationId
|
|
2339
|
+
}),
|
|
2340
|
+
onSuccess: () => resolve(),
|
|
2341
|
+
onError: error => reject(error)
|
|
2162
2342
|
})
|
|
2163
|
-
});
|
|
2343
|
+
}));
|
|
2164
2344
|
}, [pushPage, masterConfig, client, session, user]);
|
|
2165
2345
|
const handleExportPrivateKey = react.useCallback(async params => {
|
|
2166
2346
|
const {
|
|
2167
2347
|
privateKeyId,
|
|
2168
2348
|
targetPublicKey,
|
|
2169
2349
|
keyFormat,
|
|
2170
|
-
stampWith
|
|
2350
|
+
stampWith,
|
|
2351
|
+
organizationId
|
|
2171
2352
|
} = params;
|
|
2172
|
-
pushPage({
|
|
2353
|
+
return new Promise((resolve, reject) => pushPage({
|
|
2173
2354
|
key: "Export private key",
|
|
2174
2355
|
content: jsxRuntime.jsx(Export.ExportComponent, {
|
|
2175
2356
|
target: privateKeyId,
|
|
2176
2357
|
exportType: base.ExportType.PrivateKey,
|
|
2177
|
-
...(keyFormat !== undefined
|
|
2358
|
+
...(keyFormat !== undefined && {
|
|
2178
2359
|
keyFormat
|
|
2179
|
-
}
|
|
2180
|
-
...(targetPublicKey !== undefined
|
|
2360
|
+
}),
|
|
2361
|
+
...(targetPublicKey !== undefined && {
|
|
2181
2362
|
targetPublicKey
|
|
2182
|
-
}
|
|
2183
|
-
...(stampWith !== undefined
|
|
2363
|
+
}),
|
|
2364
|
+
...(stampWith !== undefined && {
|
|
2184
2365
|
stampWith
|
|
2185
|
-
}
|
|
2366
|
+
}),
|
|
2367
|
+
...(organizationId !== undefined && {
|
|
2368
|
+
organizationId
|
|
2369
|
+
}),
|
|
2370
|
+
onSuccess: () => resolve(),
|
|
2371
|
+
onError: error => reject(error)
|
|
2186
2372
|
})
|
|
2187
|
-
});
|
|
2373
|
+
}));
|
|
2188
2374
|
}, [pushPage, masterConfig, client, session, user]);
|
|
2189
2375
|
const handleExportWalletAccount = react.useCallback(async params => {
|
|
2190
2376
|
const {
|
|
2191
2377
|
address,
|
|
2192
2378
|
targetPublicKey,
|
|
2193
2379
|
keyFormat,
|
|
2194
|
-
stampWith
|
|
2380
|
+
stampWith,
|
|
2381
|
+
organizationId
|
|
2195
2382
|
} = params;
|
|
2196
|
-
pushPage({
|
|
2383
|
+
return new Promise((resolve, reject) => pushPage({
|
|
2197
2384
|
key: "Export wallet account",
|
|
2198
2385
|
content: jsxRuntime.jsx(Export.ExportComponent, {
|
|
2199
2386
|
target: address,
|
|
2200
2387
|
exportType: base.ExportType.WalletAccount,
|
|
2201
|
-
...(keyFormat !== undefined
|
|
2388
|
+
...(keyFormat !== undefined && {
|
|
2202
2389
|
keyFormat
|
|
2203
|
-
}
|
|
2204
|
-
...(targetPublicKey !== undefined
|
|
2390
|
+
}),
|
|
2391
|
+
...(targetPublicKey !== undefined && {
|
|
2205
2392
|
targetPublicKey
|
|
2206
|
-
}
|
|
2207
|
-
...(stampWith !== undefined
|
|
2393
|
+
}),
|
|
2394
|
+
...(stampWith !== undefined && {
|
|
2208
2395
|
stampWith
|
|
2209
|
-
}
|
|
2396
|
+
}),
|
|
2397
|
+
...(organizationId !== undefined && {
|
|
2398
|
+
organizationId
|
|
2399
|
+
}),
|
|
2400
|
+
onSuccess: () => resolve(),
|
|
2401
|
+
onError: error => reject(error)
|
|
2210
2402
|
})
|
|
2211
|
-
});
|
|
2403
|
+
}));
|
|
2212
2404
|
}, [pushPage, masterConfig, client, session, user]);
|
|
2213
2405
|
const handleImportWallet = react.useCallback(async params => {
|
|
2214
2406
|
const {
|
|
2215
2407
|
defaultWalletAccounts,
|
|
2216
2408
|
successPageDuration = 2000,
|
|
2217
|
-
stampWith
|
|
2409
|
+
stampWith,
|
|
2410
|
+
walletName,
|
|
2411
|
+
organizationId,
|
|
2412
|
+
userId
|
|
2218
2413
|
} = params || {};
|
|
2219
2414
|
try {
|
|
2220
2415
|
return utils.withTurnkeyErrorHandling(() => new Promise((resolve, reject) => pushPage({
|
|
@@ -2233,9 +2428,18 @@ const ClientProvider = ({
|
|
|
2233
2428
|
}),
|
|
2234
2429
|
...(stampWith !== undefined && {
|
|
2235
2430
|
stampWith
|
|
2431
|
+
}),
|
|
2432
|
+
...(walletName !== undefined && {
|
|
2433
|
+
name: walletName
|
|
2434
|
+
}),
|
|
2435
|
+
...(organizationId !== undefined && {
|
|
2436
|
+
organizationId
|
|
2437
|
+
}),
|
|
2438
|
+
...(userId !== undefined && {
|
|
2439
|
+
userId
|
|
2236
2440
|
})
|
|
2237
2441
|
})
|
|
2238
|
-
})));
|
|
2442
|
+
})), () => logout());
|
|
2239
2443
|
} catch (error) {
|
|
2240
2444
|
if (error instanceof sdkTypes.TurnkeyError) {
|
|
2241
2445
|
throw error;
|
|
@@ -2248,7 +2452,9 @@ const ClientProvider = ({
|
|
|
2248
2452
|
curve,
|
|
2249
2453
|
addressFormats,
|
|
2250
2454
|
successPageDuration = 2000,
|
|
2251
|
-
stampWith
|
|
2455
|
+
stampWith,
|
|
2456
|
+
keyName,
|
|
2457
|
+
organizationId
|
|
2252
2458
|
} = params || {};
|
|
2253
2459
|
try {
|
|
2254
2460
|
return utils.withTurnkeyErrorHandling(() => new Promise((resolve, reject) => pushPage({
|
|
@@ -2266,9 +2472,15 @@ const ClientProvider = ({
|
|
|
2266
2472
|
}),
|
|
2267
2473
|
...(stampWith !== undefined && {
|
|
2268
2474
|
stampWith
|
|
2475
|
+
}),
|
|
2476
|
+
...(keyName !== undefined && {
|
|
2477
|
+
name: keyName
|
|
2478
|
+
}),
|
|
2479
|
+
...(organizationId !== undefined && {
|
|
2480
|
+
organizationId
|
|
2269
2481
|
})
|
|
2270
2482
|
})
|
|
2271
|
-
})));
|
|
2483
|
+
})), () => logout());
|
|
2272
2484
|
} catch (error) {
|
|
2273
2485
|
if (error instanceof sdkTypes.TurnkeyError) {
|
|
2274
2486
|
throw error;
|
|
@@ -2284,8 +2496,14 @@ const ClientProvider = ({
|
|
|
2284
2496
|
stampWith
|
|
2285
2497
|
} = params || {};
|
|
2286
2498
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2287
|
-
|
|
2288
|
-
|
|
2499
|
+
const s = await getSession();
|
|
2500
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
2501
|
+
if (!organizationId) {
|
|
2502
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2503
|
+
}
|
|
2504
|
+
const userId = params?.userId || user?.userId;
|
|
2505
|
+
if (!userId) {
|
|
2506
|
+
throw new sdkTypes.TurnkeyError("A user ID is required to update a user name.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2289
2507
|
}
|
|
2290
2508
|
const onSuccess = () => {
|
|
2291
2509
|
if (!successPageDuration) return;
|
|
@@ -2316,21 +2534,26 @@ const ClientProvider = ({
|
|
|
2316
2534
|
},
|
|
2317
2535
|
successPageDuration: successPageDuration,
|
|
2318
2536
|
stampWith: stampWith,
|
|
2319
|
-
...(title !== undefined
|
|
2537
|
+
...(title !== undefined && {
|
|
2320
2538
|
title
|
|
2321
|
-
}
|
|
2322
|
-
...(subTitle !== undefined
|
|
2539
|
+
}),
|
|
2540
|
+
...(subTitle !== undefined && {
|
|
2323
2541
|
subTitle
|
|
2324
|
-
}
|
|
2542
|
+
}),
|
|
2543
|
+
organizationId: organizationId,
|
|
2544
|
+
userId: userId
|
|
2325
2545
|
}),
|
|
2326
2546
|
showTitle: false
|
|
2327
2547
|
});
|
|
2328
|
-
}));
|
|
2548
|
+
}), () => logout());
|
|
2329
2549
|
} else {
|
|
2330
2550
|
const res = await updateUserName({
|
|
2331
2551
|
userName: params.userName,
|
|
2332
2552
|
userId: user.userId,
|
|
2333
|
-
stampWith
|
|
2553
|
+
stampWith,
|
|
2554
|
+
...(organizationId !== undefined && {
|
|
2555
|
+
organizationId
|
|
2556
|
+
})
|
|
2334
2557
|
});
|
|
2335
2558
|
onSuccess();
|
|
2336
2559
|
return res;
|
|
@@ -2346,18 +2569,25 @@ const ClientProvider = ({
|
|
|
2346
2569
|
const {
|
|
2347
2570
|
successPageDuration = 2000,
|
|
2348
2571
|
subTitle,
|
|
2349
|
-
title
|
|
2572
|
+
title,
|
|
2573
|
+
stampWith
|
|
2350
2574
|
} = params || {};
|
|
2351
2575
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2352
|
-
if (!session) {
|
|
2353
|
-
throw new sdkTypes.TurnkeyError("No active session found.", sdkTypes.TurnkeyErrorCodes.NO_SESSION_FOUND);
|
|
2354
|
-
}
|
|
2355
2576
|
if (!masterConfig) {
|
|
2356
2577
|
throw new sdkTypes.TurnkeyError("Config is not ready yet!", sdkTypes.TurnkeyErrorCodes.CONFIG_NOT_INITIALIZED);
|
|
2357
2578
|
}
|
|
2358
2579
|
if (!masterConfig.auth?.methods?.smsOtpAuthEnabled) {
|
|
2359
2580
|
throw new sdkTypes.TurnkeyError("SMS OTP authentication is not enabled in the configuration.", sdkTypes.TurnkeyErrorCodes.AUTH_METHOD_NOT_ENABLED);
|
|
2360
2581
|
}
|
|
2582
|
+
const s = await getSession();
|
|
2583
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
2584
|
+
if (!organizationId) {
|
|
2585
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2586
|
+
}
|
|
2587
|
+
const userId = params?.userId || s?.userId;
|
|
2588
|
+
if (!userId) {
|
|
2589
|
+
throw new sdkTypes.TurnkeyError("A user ID is required to update a phone number.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2590
|
+
}
|
|
2361
2591
|
const onSuccess = () => {
|
|
2362
2592
|
if (!successPageDuration) return;
|
|
2363
2593
|
pushPage({
|
|
@@ -2382,16 +2612,21 @@ const ClientProvider = ({
|
|
|
2382
2612
|
successPageDuration: successPageDuration,
|
|
2383
2613
|
onSuccess: userId => resolve(userId),
|
|
2384
2614
|
onError: error => reject(error),
|
|
2385
|
-
|
|
2615
|
+
organizationId: organizationId,
|
|
2616
|
+
userId: userId,
|
|
2617
|
+
...(title !== undefined && {
|
|
2386
2618
|
title
|
|
2387
|
-
}
|
|
2388
|
-
...(subTitle !== undefined
|
|
2619
|
+
}),
|
|
2620
|
+
...(subTitle !== undefined && {
|
|
2389
2621
|
subTitle
|
|
2390
|
-
}
|
|
2622
|
+
}),
|
|
2623
|
+
...(stampWith !== undefined && {
|
|
2624
|
+
stampWith
|
|
2625
|
+
})
|
|
2391
2626
|
}),
|
|
2392
2627
|
showTitle: false
|
|
2393
2628
|
});
|
|
2394
|
-
}));
|
|
2629
|
+
}), () => logout());
|
|
2395
2630
|
} else {
|
|
2396
2631
|
const otpId = await initOtp({
|
|
2397
2632
|
otpType: core.OtpType.Sms,
|
|
@@ -2404,6 +2639,8 @@ const ClientProvider = ({
|
|
|
2404
2639
|
otpType: core.OtpType.Sms,
|
|
2405
2640
|
contact: params.phoneNumber,
|
|
2406
2641
|
otpId: otpId,
|
|
2642
|
+
otpLength: masterConfig.auth?.otpLength !== undefined ? Number(masterConfig.auth.otpLength) : undefined,
|
|
2643
|
+
alphanumeric: masterConfig.auth?.otpAlphanumeric,
|
|
2407
2644
|
onContinue: async otpCode => {
|
|
2408
2645
|
try {
|
|
2409
2646
|
const {
|
|
@@ -2417,7 +2654,11 @@ const ClientProvider = ({
|
|
|
2417
2654
|
const res = await updateUserPhoneNumber({
|
|
2418
2655
|
phoneNumber: params.phoneNumber,
|
|
2419
2656
|
verificationToken,
|
|
2420
|
-
userId
|
|
2657
|
+
userId,
|
|
2658
|
+
organizationId,
|
|
2659
|
+
...(stampWith !== undefined && {
|
|
2660
|
+
stampWith
|
|
2661
|
+
})
|
|
2421
2662
|
});
|
|
2422
2663
|
onSuccess();
|
|
2423
2664
|
resolve(res);
|
|
@@ -2437,7 +2678,7 @@ const ClientProvider = ({
|
|
|
2437
2678
|
}),
|
|
2438
2679
|
showTitle: false
|
|
2439
2680
|
});
|
|
2440
|
-
}), callbacks, "Failed to update phone number");
|
|
2681
|
+
}), () => logout(), callbacks, "Failed to update phone number");
|
|
2441
2682
|
}
|
|
2442
2683
|
} catch (error) {
|
|
2443
2684
|
if (error instanceof sdkTypes.TurnkeyError) {
|
|
@@ -2450,11 +2691,18 @@ const ClientProvider = ({
|
|
|
2450
2691
|
const {
|
|
2451
2692
|
successPageDuration = 2000,
|
|
2452
2693
|
subTitle,
|
|
2453
|
-
title
|
|
2694
|
+
title,
|
|
2695
|
+
stampWith
|
|
2454
2696
|
} = params || {};
|
|
2455
2697
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2456
|
-
|
|
2457
|
-
|
|
2698
|
+
const s = await getSession();
|
|
2699
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
2700
|
+
if (!organizationId) {
|
|
2701
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2702
|
+
}
|
|
2703
|
+
const userId = params?.userId || s?.userId;
|
|
2704
|
+
if (!userId) {
|
|
2705
|
+
throw new sdkTypes.TurnkeyError("A user ID is required to update an email.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2458
2706
|
}
|
|
2459
2707
|
const onSuccess = () => {
|
|
2460
2708
|
if (!successPageDuration) return;
|
|
@@ -2482,16 +2730,21 @@ const ClientProvider = ({
|
|
|
2482
2730
|
resolve(userId);
|
|
2483
2731
|
},
|
|
2484
2732
|
onError: error => reject(error),
|
|
2485
|
-
|
|
2733
|
+
organizationId: organizationId,
|
|
2734
|
+
userId: userId,
|
|
2735
|
+
...(title !== undefined && {
|
|
2486
2736
|
title
|
|
2487
|
-
}
|
|
2488
|
-
...(subTitle !== undefined
|
|
2737
|
+
}),
|
|
2738
|
+
...(subTitle !== undefined && {
|
|
2489
2739
|
subTitle
|
|
2490
|
-
}
|
|
2740
|
+
}),
|
|
2741
|
+
...(stampWith !== undefined && {
|
|
2742
|
+
stampWith
|
|
2743
|
+
})
|
|
2491
2744
|
}),
|
|
2492
2745
|
showTitle: false
|
|
2493
2746
|
});
|
|
2494
|
-
}));
|
|
2747
|
+
}), () => logout());
|
|
2495
2748
|
} else {
|
|
2496
2749
|
const otpId = await initOtp({
|
|
2497
2750
|
otpType: core.OtpType.Email,
|
|
@@ -2504,6 +2757,8 @@ const ClientProvider = ({
|
|
|
2504
2757
|
otpType: core.OtpType.Email,
|
|
2505
2758
|
contact: params.email,
|
|
2506
2759
|
otpId: otpId,
|
|
2760
|
+
otpLength: masterConfig?.auth?.otpLength !== undefined ? Number(masterConfig.auth.otpLength) : undefined,
|
|
2761
|
+
alphanumeric: masterConfig?.auth?.otpAlphanumeric,
|
|
2507
2762
|
onContinue: async otpCode => {
|
|
2508
2763
|
try {
|
|
2509
2764
|
const {
|
|
@@ -2517,7 +2772,11 @@ const ClientProvider = ({
|
|
|
2517
2772
|
const res = await updateUserEmail({
|
|
2518
2773
|
email: params.email,
|
|
2519
2774
|
verificationToken,
|
|
2520
|
-
userId
|
|
2775
|
+
userId,
|
|
2776
|
+
organizationId,
|
|
2777
|
+
...(stampWith !== undefined && {
|
|
2778
|
+
stampWith
|
|
2779
|
+
})
|
|
2521
2780
|
});
|
|
2522
2781
|
onSuccess();
|
|
2523
2782
|
resolve(res);
|
|
@@ -2534,7 +2793,7 @@ const ClientProvider = ({
|
|
|
2534
2793
|
}),
|
|
2535
2794
|
showTitle: false
|
|
2536
2795
|
});
|
|
2537
|
-
}), callbacks, "Failed to update email");
|
|
2796
|
+
}), () => logout(), callbacks, "Failed to update email");
|
|
2538
2797
|
}
|
|
2539
2798
|
} catch (error) {
|
|
2540
2799
|
if (error instanceof sdkTypes.TurnkeyError) {
|
|
@@ -2547,13 +2806,20 @@ const ClientProvider = ({
|
|
|
2547
2806
|
const {
|
|
2548
2807
|
successPageDuration = 2000,
|
|
2549
2808
|
subTitle,
|
|
2550
|
-
title
|
|
2809
|
+
title,
|
|
2810
|
+
stampWith
|
|
2551
2811
|
} = params || {};
|
|
2552
2812
|
if (!client) {
|
|
2553
2813
|
throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2554
2814
|
}
|
|
2555
|
-
|
|
2556
|
-
|
|
2815
|
+
const s = await getSession();
|
|
2816
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
2817
|
+
if (!organizationId) {
|
|
2818
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2819
|
+
}
|
|
2820
|
+
const userId = params?.userId || s?.userId;
|
|
2821
|
+
if (!userId) {
|
|
2822
|
+
throw new sdkTypes.TurnkeyError("A user ID is required to add an email.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2557
2823
|
}
|
|
2558
2824
|
const onSuccess = () => {
|
|
2559
2825
|
if (!successPageDuration) return;
|
|
@@ -2586,11 +2852,14 @@ const ClientProvider = ({
|
|
|
2586
2852
|
} : {}),
|
|
2587
2853
|
...(subTitle !== undefined ? {
|
|
2588
2854
|
subTitle
|
|
2589
|
-
} : {})
|
|
2855
|
+
} : {}),
|
|
2856
|
+
organizationId: organizationId,
|
|
2857
|
+
userId: userId,
|
|
2858
|
+
stampWith: stampWith
|
|
2590
2859
|
}),
|
|
2591
2860
|
showTitle: false
|
|
2592
2861
|
});
|
|
2593
|
-
}));
|
|
2862
|
+
}), () => logout());
|
|
2594
2863
|
} else {
|
|
2595
2864
|
const otpId = await initOtp({
|
|
2596
2865
|
otpType: core.OtpType.Email,
|
|
@@ -2603,6 +2872,8 @@ const ClientProvider = ({
|
|
|
2603
2872
|
otpType: core.OtpType.Email,
|
|
2604
2873
|
contact: params.email,
|
|
2605
2874
|
otpId: otpId,
|
|
2875
|
+
otpLength: masterConfig?.auth?.otpLength !== undefined ? Number(masterConfig.auth.otpLength) : undefined,
|
|
2876
|
+
alphanumeric: masterConfig?.auth?.otpAlphanumeric,
|
|
2606
2877
|
onContinue: async otpCode => {
|
|
2607
2878
|
try {
|
|
2608
2879
|
const {
|
|
@@ -2616,7 +2887,9 @@ const ClientProvider = ({
|
|
|
2616
2887
|
const res = await updateUserEmail({
|
|
2617
2888
|
email: params.email,
|
|
2618
2889
|
verificationToken,
|
|
2619
|
-
userId
|
|
2890
|
+
userId,
|
|
2891
|
+
organizationId,
|
|
2892
|
+
stampWith
|
|
2620
2893
|
});
|
|
2621
2894
|
onSuccess();
|
|
2622
2895
|
resolve(res);
|
|
@@ -2633,7 +2906,7 @@ const ClientProvider = ({
|
|
|
2633
2906
|
}),
|
|
2634
2907
|
showTitle: false
|
|
2635
2908
|
});
|
|
2636
|
-
}), callbacks, "Failed to add email");
|
|
2909
|
+
}), () => logout(), callbacks, "Failed to add email");
|
|
2637
2910
|
}
|
|
2638
2911
|
} catch (error) {
|
|
2639
2912
|
if (error instanceof sdkTypes.TurnkeyError) {
|
|
@@ -2646,18 +2919,25 @@ const ClientProvider = ({
|
|
|
2646
2919
|
const {
|
|
2647
2920
|
successPageDuration = 2000,
|
|
2648
2921
|
subTitle,
|
|
2649
|
-
title
|
|
2922
|
+
title,
|
|
2923
|
+
stampWith
|
|
2650
2924
|
} = params || {};
|
|
2651
2925
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2652
|
-
if (!session) {
|
|
2653
|
-
throw new sdkTypes.TurnkeyError("No active session found.", sdkTypes.TurnkeyErrorCodes.NO_SESSION_FOUND);
|
|
2654
|
-
}
|
|
2655
2926
|
if (!masterConfig) {
|
|
2656
2927
|
throw new sdkTypes.TurnkeyError("Config is not ready yet!", sdkTypes.TurnkeyErrorCodes.CONFIG_NOT_INITIALIZED);
|
|
2657
2928
|
}
|
|
2658
2929
|
if (!masterConfig.auth?.methods?.smsOtpAuthEnabled) {
|
|
2659
2930
|
throw new sdkTypes.TurnkeyError("SMS OTP authentication is not enabled in the configuration.", sdkTypes.TurnkeyErrorCodes.AUTH_METHOD_NOT_ENABLED);
|
|
2660
2931
|
}
|
|
2932
|
+
const s = await getSession();
|
|
2933
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
2934
|
+
if (!organizationId) {
|
|
2935
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2936
|
+
}
|
|
2937
|
+
const userId = params?.userId || s?.userId;
|
|
2938
|
+
if (!userId) {
|
|
2939
|
+
throw new sdkTypes.TurnkeyError("A user ID is required to add a phone number.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2940
|
+
}
|
|
2661
2941
|
const onSuccess = () => {
|
|
2662
2942
|
if (!successPageDuration) return;
|
|
2663
2943
|
pushPage({
|
|
@@ -2691,11 +2971,14 @@ const ClientProvider = ({
|
|
|
2691
2971
|
}),
|
|
2692
2972
|
...(subTitle !== undefined && {
|
|
2693
2973
|
subTitle
|
|
2694
|
-
})
|
|
2974
|
+
}),
|
|
2975
|
+
organizationId: organizationId,
|
|
2976
|
+
userId: userId,
|
|
2977
|
+
stampWith: stampWith
|
|
2695
2978
|
}),
|
|
2696
2979
|
showTitle: false
|
|
2697
2980
|
});
|
|
2698
|
-
}), callbacks, "Failed to add phone number");
|
|
2981
|
+
}), () => logout(), callbacks, "Failed to add phone number");
|
|
2699
2982
|
} else {
|
|
2700
2983
|
const otpId = await initOtp({
|
|
2701
2984
|
otpType: core.OtpType.Sms,
|
|
@@ -2708,6 +2991,8 @@ const ClientProvider = ({
|
|
|
2708
2991
|
otpType: core.OtpType.Sms,
|
|
2709
2992
|
contact: params.phoneNumber,
|
|
2710
2993
|
otpId: otpId,
|
|
2994
|
+
otpLength: masterConfig.auth?.otpLength !== undefined ? Number(masterConfig.auth.otpLength) : undefined,
|
|
2995
|
+
alphanumeric: masterConfig?.auth?.otpAlphanumeric,
|
|
2711
2996
|
onContinue: async otpCode => {
|
|
2712
2997
|
try {
|
|
2713
2998
|
const {
|
|
@@ -2721,7 +3006,9 @@ const ClientProvider = ({
|
|
|
2721
3006
|
const res = await updateUserPhoneNumber({
|
|
2722
3007
|
phoneNumber: params.phoneNumber,
|
|
2723
3008
|
verificationToken,
|
|
2724
|
-
userId: user.userId
|
|
3009
|
+
userId: user.userId,
|
|
3010
|
+
organizationId,
|
|
3011
|
+
stampWith
|
|
2725
3012
|
});
|
|
2726
3013
|
onSuccess();
|
|
2727
3014
|
resolve(res);
|
|
@@ -2741,7 +3028,7 @@ const ClientProvider = ({
|
|
|
2741
3028
|
}),
|
|
2742
3029
|
showTitle: false
|
|
2743
3030
|
});
|
|
2744
|
-
}), callbacks, "Failed to add phone number");
|
|
3031
|
+
}), () => logout(), callbacks, "Failed to add phone number");
|
|
2745
3032
|
}
|
|
2746
3033
|
} catch (error) {
|
|
2747
3034
|
if (error instanceof sdkTypes.TurnkeyError) {
|
|
@@ -2760,8 +3047,10 @@ const ClientProvider = ({
|
|
|
2760
3047
|
userId
|
|
2761
3048
|
} = params;
|
|
2762
3049
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2763
|
-
|
|
2764
|
-
|
|
3050
|
+
const s = await getSession();
|
|
3051
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
3052
|
+
if (!organizationId) {
|
|
3053
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2765
3054
|
}
|
|
2766
3055
|
return utils.withTurnkeyErrorHandling(() => new Promise((resolve, reject) => {
|
|
2767
3056
|
pushPage({
|
|
@@ -2784,12 +3073,15 @@ const ClientProvider = ({
|
|
|
2784
3073
|
}),
|
|
2785
3074
|
...(subTitle !== undefined && {
|
|
2786
3075
|
subTitle
|
|
3076
|
+
}),
|
|
3077
|
+
...(organizationId !== undefined && {
|
|
3078
|
+
organizationId
|
|
2787
3079
|
})
|
|
2788
3080
|
}),
|
|
2789
3081
|
showTitle: false,
|
|
2790
3082
|
preventBack: true
|
|
2791
3083
|
});
|
|
2792
|
-
}), callbacks, "Failed to remove passkey");
|
|
3084
|
+
}), () => logout(), callbacks, "Failed to remove passkey");
|
|
2793
3085
|
}, [pushPage, masterConfig, client, session, user]);
|
|
2794
3086
|
const handleAddPasskey = react.useCallback(async params => {
|
|
2795
3087
|
const {
|
|
@@ -2799,10 +3091,15 @@ const ClientProvider = ({
|
|
|
2799
3091
|
stampWith
|
|
2800
3092
|
} = params || {};
|
|
2801
3093
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2802
|
-
|
|
2803
|
-
|
|
3094
|
+
const s = await getSession();
|
|
3095
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
3096
|
+
if (!organizationId) {
|
|
3097
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
3098
|
+
}
|
|
3099
|
+
const userId = params?.userId || s?.userId;
|
|
3100
|
+
if (!userId) {
|
|
3101
|
+
throw new sdkTypes.TurnkeyError("A user ID or a valid session is required to add a passkey.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2804
3102
|
}
|
|
2805
|
-
const userId = params?.userId || session.userId;
|
|
2806
3103
|
try {
|
|
2807
3104
|
const resPromise = addPasskey({
|
|
2808
3105
|
...(name && {
|
|
@@ -2812,7 +3109,10 @@ const ClientProvider = ({
|
|
|
2812
3109
|
displayName
|
|
2813
3110
|
}),
|
|
2814
3111
|
userId,
|
|
2815
|
-
stampWith
|
|
3112
|
+
stampWith,
|
|
3113
|
+
...(organizationId && {
|
|
3114
|
+
organizationId
|
|
3115
|
+
})
|
|
2816
3116
|
});
|
|
2817
3117
|
resPromise.then(() => {
|
|
2818
3118
|
pushPage({
|
|
@@ -2845,8 +3145,10 @@ const ClientProvider = ({
|
|
|
2845
3145
|
stampWith
|
|
2846
3146
|
} = params;
|
|
2847
3147
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2848
|
-
|
|
2849
|
-
|
|
3148
|
+
const s = await getSession();
|
|
3149
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
3150
|
+
if (!organizationId) {
|
|
3151
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2850
3152
|
}
|
|
2851
3153
|
try {
|
|
2852
3154
|
return new Promise((resolve, reject) => {
|
|
@@ -2867,10 +3169,14 @@ const ClientProvider = ({
|
|
|
2867
3169
|
}),
|
|
2868
3170
|
...(subTitle !== undefined && {
|
|
2869
3171
|
subTitle
|
|
3172
|
+
}),
|
|
3173
|
+
...(organizationId !== undefined && {
|
|
3174
|
+
organizationId
|
|
2870
3175
|
})
|
|
2871
3176
|
}),
|
|
2872
3177
|
showTitle: false,
|
|
2873
|
-
preventBack: true
|
|
3178
|
+
preventBack: true,
|
|
3179
|
+
onClose: () => reject(new sdkTypes.TurnkeyError("User cancelled the remove OAuth provider process.", sdkTypes.TurnkeyErrorCodes.USER_CANCELED))
|
|
2874
3180
|
});
|
|
2875
3181
|
});
|
|
2876
3182
|
} catch (error) {
|
|
@@ -2882,97 +3188,117 @@ const ClientProvider = ({
|
|
|
2882
3188
|
}, [pushPage, masterConfig, client, session, user]);
|
|
2883
3189
|
const handleAddOauthProvider = react.useCallback(async params => {
|
|
2884
3190
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2885
|
-
if (!session) {
|
|
2886
|
-
throw new sdkTypes.TurnkeyError("No active session found.", sdkTypes.TurnkeyErrorCodes.NO_SESSION_FOUND);
|
|
2887
|
-
}
|
|
2888
3191
|
const {
|
|
2889
3192
|
providerName,
|
|
2890
|
-
stampWith
|
|
3193
|
+
stampWith,
|
|
3194
|
+
successPageDuration = 2000
|
|
2891
3195
|
} = params;
|
|
2892
|
-
const
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
};
|
|
2911
|
-
switch (providerName) {
|
|
2912
|
-
case sdkTypes.OAuthProviders.DISCORD:
|
|
2913
|
-
{
|
|
2914
|
-
await handleDiscordOauth({
|
|
2915
|
-
openInPage: false,
|
|
2916
|
-
onOauthSuccess
|
|
2917
|
-
});
|
|
2918
|
-
break;
|
|
2919
|
-
}
|
|
2920
|
-
case sdkTypes.OAuthProviders.X:
|
|
2921
|
-
{
|
|
2922
|
-
await handleXOauth({
|
|
2923
|
-
openInPage: false,
|
|
2924
|
-
onOauthSuccess
|
|
2925
|
-
});
|
|
2926
|
-
break;
|
|
2927
|
-
}
|
|
2928
|
-
case sdkTypes.OAuthProviders.GOOGLE:
|
|
2929
|
-
{
|
|
2930
|
-
await handleGoogleOauth({
|
|
2931
|
-
openInPage: false,
|
|
2932
|
-
onOauthSuccess
|
|
2933
|
-
});
|
|
2934
|
-
break;
|
|
2935
|
-
}
|
|
2936
|
-
case sdkTypes.OAuthProviders.APPLE:
|
|
2937
|
-
{
|
|
2938
|
-
await handleAppleOauth({
|
|
2939
|
-
openInPage: false,
|
|
2940
|
-
onOauthSuccess
|
|
3196
|
+
const s = await getSession();
|
|
3197
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
3198
|
+
if (!organizationId) {
|
|
3199
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
3200
|
+
}
|
|
3201
|
+
const userId = params?.userId || s?.userId;
|
|
3202
|
+
if (!userId) {
|
|
3203
|
+
throw new sdkTypes.TurnkeyError("A user ID is required to add an OAuth provider.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
3204
|
+
}
|
|
3205
|
+
return new Promise(async (resolve, reject) => {
|
|
3206
|
+
try {
|
|
3207
|
+
const onOauthSuccess = async params => {
|
|
3208
|
+
await addOauthProvider({
|
|
3209
|
+
providerName: params.providerName,
|
|
3210
|
+
oidcToken: params.oidcToken,
|
|
3211
|
+
stampWith,
|
|
3212
|
+
organizationId,
|
|
3213
|
+
userId
|
|
2941
3214
|
});
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
3215
|
+
resolve();
|
|
3216
|
+
pushPage({
|
|
3217
|
+
key: "OAuth Provider Added",
|
|
3218
|
+
content: jsxRuntime.jsx(Success.SuccessPage, {
|
|
3219
|
+
text: `Successfully added ${params.providerName} OAuth provider!`,
|
|
3220
|
+
duration: successPageDuration,
|
|
3221
|
+
onComplete: () => {
|
|
3222
|
+
closeModal();
|
|
3223
|
+
}
|
|
3224
|
+
}),
|
|
3225
|
+
preventBack: true,
|
|
3226
|
+
showTitle: false
|
|
2949
3227
|
});
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
3228
|
+
};
|
|
3229
|
+
switch (providerName) {
|
|
3230
|
+
case sdkTypes.OAuthProviders.DISCORD:
|
|
3231
|
+
{
|
|
3232
|
+
return await handleDiscordOauth({
|
|
3233
|
+
openInPage: false,
|
|
3234
|
+
onOauthSuccess
|
|
3235
|
+
});
|
|
3236
|
+
}
|
|
3237
|
+
case sdkTypes.OAuthProviders.X:
|
|
3238
|
+
{
|
|
3239
|
+
return await handleXOauth({
|
|
3240
|
+
openInPage: false,
|
|
3241
|
+
onOauthSuccess
|
|
3242
|
+
});
|
|
3243
|
+
}
|
|
3244
|
+
case sdkTypes.OAuthProviders.GOOGLE:
|
|
3245
|
+
{
|
|
3246
|
+
return await handleGoogleOauth({
|
|
3247
|
+
openInPage: false,
|
|
3248
|
+
onOauthSuccess
|
|
3249
|
+
});
|
|
3250
|
+
}
|
|
3251
|
+
case sdkTypes.OAuthProviders.APPLE:
|
|
3252
|
+
{
|
|
3253
|
+
return await handleAppleOauth({
|
|
3254
|
+
openInPage: false,
|
|
3255
|
+
onOauthSuccess
|
|
3256
|
+
});
|
|
3257
|
+
}
|
|
3258
|
+
case sdkTypes.OAuthProviders.FACEBOOK:
|
|
3259
|
+
{
|
|
3260
|
+
return await handleFacebookOauth({
|
|
3261
|
+
openInPage: false,
|
|
3262
|
+
onOauthSuccess
|
|
3263
|
+
});
|
|
3264
|
+
}
|
|
3265
|
+
default:
|
|
3266
|
+
{
|
|
3267
|
+
throw new sdkTypes.TurnkeyError(`Unsupported OAuth provider: ${providerName}`, sdkTypes.TurnkeyErrorCodes.NOT_FOUND);
|
|
3268
|
+
}
|
|
2955
3269
|
}
|
|
2956
|
-
|
|
3270
|
+
} catch (error) {
|
|
3271
|
+
reject(error);
|
|
3272
|
+
}
|
|
3273
|
+
});
|
|
2957
3274
|
}, [pushPage, masterConfig, client, session, user]);
|
|
2958
3275
|
const handleConnectExternalWallet = react.useCallback(async params => {
|
|
2959
3276
|
const {
|
|
2960
3277
|
successPageDuration = 2000
|
|
2961
3278
|
} = params || {};
|
|
2962
3279
|
if (!client) throw new sdkTypes.TurnkeyError("Client is not initialized.", sdkTypes.TurnkeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
2963
|
-
if (!session) {
|
|
2964
|
-
throw new sdkTypes.TurnkeyError("No active session found.", sdkTypes.TurnkeyErrorCodes.NO_SESSION_FOUND);
|
|
2965
|
-
}
|
|
2966
3280
|
if (!masterConfig?.walletConfig?.features?.connecting) {
|
|
2967
3281
|
throw new sdkTypes.TurnkeyError("Wallet connecting is not enabled.", sdkTypes.TurnkeyErrorCodes.FEATURE_NOT_ENABLED);
|
|
2968
3282
|
}
|
|
2969
3283
|
const providers = await fetchWalletProviders();
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
3284
|
+
return new Promise((resolve, reject) => {
|
|
3285
|
+
pushPage({
|
|
3286
|
+
key: "Connect wallet",
|
|
3287
|
+
content: jsxRuntime.jsx(ConnectWallet.ConnectWalletModal, {
|
|
3288
|
+
providers: providers,
|
|
3289
|
+
successPageDuration: successPageDuration,
|
|
3290
|
+
onSuccess: (type, account) => {
|
|
3291
|
+
resolve({
|
|
3292
|
+
type,
|
|
3293
|
+
account
|
|
3294
|
+
});
|
|
3295
|
+
},
|
|
3296
|
+
onError: error => {
|
|
3297
|
+
reject(error);
|
|
3298
|
+
}
|
|
3299
|
+
}),
|
|
3300
|
+
onClose: () => reject(new sdkTypes.TurnkeyError("User cancelled the connect wallet process.", sdkTypes.TurnkeyErrorCodes.USER_CANCELED))
|
|
3301
|
+
});
|
|
2976
3302
|
});
|
|
2977
3303
|
}, [pushPage, masterConfig, client, session, user]);
|
|
2978
3304
|
const handleRemoveUserEmail = react.useCallback(async params => {
|
|
@@ -2981,8 +3307,10 @@ const ClientProvider = ({
|
|
|
2981
3307
|
stampWith,
|
|
2982
3308
|
userId
|
|
2983
3309
|
} = params || {};
|
|
2984
|
-
|
|
2985
|
-
|
|
3310
|
+
const s = await getSession();
|
|
3311
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
3312
|
+
if (!organizationId) {
|
|
3313
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
2986
3314
|
}
|
|
2987
3315
|
try {
|
|
2988
3316
|
return new Promise((resolve, reject) => {
|
|
@@ -3001,10 +3329,14 @@ const ClientProvider = ({
|
|
|
3001
3329
|
},
|
|
3002
3330
|
onError: error => {
|
|
3003
3331
|
reject(error);
|
|
3004
|
-
}
|
|
3332
|
+
},
|
|
3333
|
+
...(organizationId !== undefined && {
|
|
3334
|
+
organizationId
|
|
3335
|
+
})
|
|
3005
3336
|
}),
|
|
3006
3337
|
showTitle: false,
|
|
3007
|
-
preventBack: true
|
|
3338
|
+
preventBack: true,
|
|
3339
|
+
onClose: () => reject(new sdkTypes.TurnkeyError("User cancelled the remove email process.", sdkTypes.TurnkeyErrorCodes.USER_CANCELED))
|
|
3008
3340
|
});
|
|
3009
3341
|
});
|
|
3010
3342
|
} catch (error) {
|
|
@@ -3020,8 +3352,10 @@ const ClientProvider = ({
|
|
|
3020
3352
|
stampWith,
|
|
3021
3353
|
userId
|
|
3022
3354
|
} = params || {};
|
|
3023
|
-
|
|
3024
|
-
|
|
3355
|
+
const s = await getSession();
|
|
3356
|
+
const organizationId = params?.organizationId || s?.organizationId;
|
|
3357
|
+
if (!organizationId) {
|
|
3358
|
+
throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
|
|
3025
3359
|
}
|
|
3026
3360
|
try {
|
|
3027
3361
|
return new Promise((resolve, reject) => {
|
|
@@ -3040,10 +3374,14 @@ const ClientProvider = ({
|
|
|
3040
3374
|
},
|
|
3041
3375
|
onError: error => {
|
|
3042
3376
|
reject(error);
|
|
3043
|
-
}
|
|
3377
|
+
},
|
|
3378
|
+
...(organizationId !== undefined && {
|
|
3379
|
+
organizationId
|
|
3380
|
+
})
|
|
3044
3381
|
}),
|
|
3045
3382
|
showTitle: false,
|
|
3046
|
-
preventBack: true
|
|
3383
|
+
preventBack: true,
|
|
3384
|
+
onClose: () => reject(new sdkTypes.TurnkeyError("User cancelled the remove phone number process.", sdkTypes.TurnkeyErrorCodes.USER_CANCELED))
|
|
3047
3385
|
});
|
|
3048
3386
|
});
|
|
3049
3387
|
} catch (error) {
|
|
@@ -3089,23 +3427,29 @@ const ClientProvider = ({
|
|
|
3089
3427
|
* only trigger `refreshWallets()` once.
|
|
3090
3428
|
*
|
|
3091
3429
|
* Defining the debounced function outside of the `useEffect` ensures all event
|
|
3092
|
-
* listeners in `
|
|
3430
|
+
* listeners in `initializeWalletProviderListeners` share the same instance, instead of creating
|
|
3093
3431
|
* a new one on every render.
|
|
3094
3432
|
*/
|
|
3095
3433
|
const debouncedRefreshWallets = utils.useDebouncedCallback(refreshWallets, 100);
|
|
3434
|
+
const debouncedFetchWalletProviders = utils.useDebouncedCallback(fetchWalletProviders, 100);
|
|
3096
3435
|
react.useEffect(() => {
|
|
3097
3436
|
if (!client) return;
|
|
3098
|
-
const
|
|
3437
|
+
const handleUpdateState = async () => {
|
|
3099
3438
|
// we only refresh the wallets if there is an active session
|
|
3100
3439
|
// this is needed because a disconnect event can occur
|
|
3101
3440
|
// while the user is unauthenticated
|
|
3441
|
+
//
|
|
3442
|
+
// WalletProviders state is updated regardless of session state
|
|
3102
3443
|
if (session) {
|
|
3103
|
-
// this
|
|
3444
|
+
// this updates both the wallets and walletProviders state
|
|
3104
3445
|
await debouncedRefreshWallets();
|
|
3446
|
+
} else {
|
|
3447
|
+
// this updates only the walletProviders state
|
|
3448
|
+
await debouncedFetchWalletProviders();
|
|
3105
3449
|
}
|
|
3106
3450
|
};
|
|
3107
3451
|
let cleanup = () => {};
|
|
3108
|
-
initializeWalletProviderListeners(walletProviders,
|
|
3452
|
+
initializeWalletProviderListeners(walletProviders, handleUpdateState).then(fn => {
|
|
3109
3453
|
cleanup = fn;
|
|
3110
3454
|
}).catch(err => {
|
|
3111
3455
|
console.error("Failed to init providers:", err);
|
|
@@ -3113,7 +3457,7 @@ const ClientProvider = ({
|
|
|
3113
3457
|
return () => {
|
|
3114
3458
|
cleanup();
|
|
3115
3459
|
};
|
|
3116
|
-
}, [client, walletProviders]);
|
|
3460
|
+
}, [client, walletProviders, session]);
|
|
3117
3461
|
react.useEffect(() => {
|
|
3118
3462
|
// 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.
|
|
3119
3463
|
// This will ensure that they are always in sync and remove the need to setAuthState manually in other places.
|
|
@@ -3128,6 +3472,11 @@ const ClientProvider = ({
|
|
|
3128
3472
|
if (!client || !masterConfig) return;
|
|
3129
3473
|
completeRedirectOauth().finally(() => {
|
|
3130
3474
|
clearSessionTimeouts();
|
|
3475
|
+
// if auth or wallet connecting features are enabled, we want to fetch
|
|
3476
|
+
// the wallet providers to set the state
|
|
3477
|
+
if (masterConfig.walletConfig?.features?.auth || masterConfig.walletConfig?.features?.connecting) {
|
|
3478
|
+
fetchWalletProviders();
|
|
3479
|
+
}
|
|
3131
3480
|
initializeSessions().finally(() => {
|
|
3132
3481
|
// Set the client state to ready only after all initializations are done.
|
|
3133
3482
|
setClientState(base.ClientState.Ready);
|
|
@@ -3145,6 +3494,7 @@ const ClientProvider = ({
|
|
|
3145
3494
|
authState,
|
|
3146
3495
|
user,
|
|
3147
3496
|
wallets,
|
|
3497
|
+
walletProviders,
|
|
3148
3498
|
config: masterConfig,
|
|
3149
3499
|
httpClient: client?.httpClient,
|
|
3150
3500
|
createPasskey,
|