diff --git a/.changeset/gold-vans-swim.md b/.changeset/gold-vans-swim.md new file mode 100644 index 0000000000..3fcd9f8f95 --- /dev/null +++ b/.changeset/gold-vans-swim.md @@ -0,0 +1,5 @@ +--- +"@clerk/clerk-js": patch +--- + +Handle gracefully Coinbase Wallet initial configuration diff --git a/packages/clerk-js/src/core/resources/SignUp.ts b/packages/clerk-js/src/core/resources/SignUp.ts index 1700a4aa9f..a2ab627814 100644 --- a/packages/clerk-js/src/core/resources/SignUp.ts +++ b/packages/clerk-js/src/core/resources/SignUp.ts @@ -207,7 +207,24 @@ export class SignUp extends BaseResource implements SignUpResource { clerkVerifyWeb3WalletCalledBeforeCreate('SignUp'); } - const signature = await generateSignature({ identifier, nonce, provider }); + let signature: string; + try { + signature = await generateSignature({ identifier, nonce, provider }); + } catch (err) { + // There is a chance that as a first time visitor when you try to setup and use the + // Coinbase Wallet from scratch in order to authenticate, the initial generate + // signature request to be rejected. For this reason we retry the request once more + // in order for the flow to be able to be completed successfully. + // + // error code 4001 means the user rejected the request + // Reference: https://docs.cdp.coinbase.com/wallet-sdk/docs/errors + if (provider === 'coinbase_wallet' && err.code === 4001) { + signature = await generateSignature({ identifier, nonce, provider }); + } else { + throw err; + } + } + return this.attemptWeb3WalletVerification({ signature, strategy }); };