Skip to content

Commit

Permalink
fix(clerk-js): Handle gracefully Coinbase Wallet use of existing Passkey
Browse files Browse the repository at this point in the history
There is a chance that as a user when you try to setup and use the Coinbase Wallet with
an existing Passkey 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.
  • Loading branch information
chanioxaris committed Oct 8, 2024
1 parent d546ea2 commit 3a6b163
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/clerk-js/src/core/resources/SignIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,22 @@ export class SignIn extends BaseResource implements SignInResource {
clerkVerifyWeb3WalletCalledBeforeCreate('SignIn');
}

const signature = await generateSignature({
identifier: this.identifier!,
nonce: nonce,
provider,
});
let signature: string;
try {
signature = await generateSignature({ identifier, nonce, provider });
} catch (err) {
// There is a chance that as a user when you try to setup and use the Coinbase Wallet with an existing
// Passkey 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.attemptFirstFactor({
signature,
Expand Down

0 comments on commit 3a6b163

Please sign in to comment.