File tree 8 files changed +41
-4
lines changed
8 files changed +41
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @clerk/localizations ' : patch
3
+ ' @clerk/clerk-js ' : patch
4
+ ' @clerk/types ' : patch
5
+ ---
6
+
7
+ Improve error handling when trying to sign-in/sign-up with web3 wallet and wallet is not installed in the browser
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import { useCardState } from '../../elements/contexts';
8
8
import type { SocialButtonsProps } from '../../elements/SocialButtons' ;
9
9
import { SocialButtons } from '../../elements/SocialButtons' ;
10
10
import { useRouter } from '../../router' ;
11
- import { handleError } from '../../utils' ;
11
+ import { handleError , web3CallbackErrorHandler } from '../../utils' ;
12
12
13
13
export const SignInSocialButtons = React . memo ( ( props : SocialButtonsProps ) => {
14
14
const clerk = useClerk ( ) ;
@@ -36,7 +36,7 @@ export const SignInSocialButtons = React.memo((props: SocialButtonsProps) => {
36
36
signUpContinueUrl : ctx . signUpContinueUrl ,
37
37
strategy,
38
38
} )
39
- . catch ( err => handleError ( err , [ ] , card . setError ) ) ;
39
+ . catch ( err => web3CallbackErrorHandler ( err , card . setError ) ) ;
40
40
} }
41
41
/>
42
42
) ;
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { useCardState } from '../../elements';
7
7
import type { SocialButtonsProps } from '../../elements/SocialButtons' ;
8
8
import { SocialButtons } from '../../elements/SocialButtons' ;
9
9
import { useRouter } from '../../router' ;
10
- import { handleError } from '../../utils' ;
10
+ import { handleError , web3CallbackErrorHandler } from '../../utils' ;
11
11
12
12
export type SignUpSocialButtonsProps = SocialButtonsProps & { continueSignUp ?: boolean ; legalAccepted ?: boolean } ;
13
13
@@ -46,7 +46,7 @@ export const SignUpSocialButtons = React.memo((props: SignUpSocialButtonsProps)
46
46
strategy,
47
47
legalAccepted : props . legalAccepted ,
48
48
} )
49
- . catch ( err => handleError ( err , [ ] , card . setError ) ) ;
49
+ . catch ( err => web3CallbackErrorHandler ( err , card . setError ) ) ;
50
50
} }
51
51
/>
52
52
) ;
Original file line number Diff line number Diff line change @@ -24,3 +24,4 @@ export * from './ExternalElementMounter';
24
24
export * from './colorOptionToHslaScale' ;
25
25
export * from './createCustomMenuItems' ;
26
26
export * from './usernameUtils' ;
27
+ export * from './web3CallbackErrorHandler' ;
Original file line number Diff line number Diff line change
1
+ import { ClerkRuntimeError , isClerkAPIResponseError } from '@clerk/shared/error' ;
2
+ import type { ClerkAPIError , ClerkRuntimeError as ClerkRuntimeErrorType } from '@clerk/types' ;
3
+
4
+ import { handleError } from './errorHandler' ;
5
+
6
+ type Web3CallbackErrorHandler = {
7
+ ( err : any , setError ?: ( err : ClerkRuntimeErrorType | ClerkAPIError | string | undefined ) => void ) : void ;
8
+ } ;
9
+
10
+ export const web3CallbackErrorHandler : Web3CallbackErrorHandler = ( err , setError ) => {
11
+ if (
12
+ isClerkAPIResponseError ( err ) &&
13
+ err . errors [ 0 ] . meta ?. paramName === 'identifier' &&
14
+ err . errors [ 0 ] . code === 'form_param_nil'
15
+ ) {
16
+ const error = new ClerkRuntimeError ( 'A Web3 Wallet extension cannot be found. Please install one to continue.' , {
17
+ code : 'web3_missing_identifier' ,
18
+ } ) ;
19
+
20
+ return handleError ( error , [ ] , setError ) ;
21
+ }
22
+ return handleError ( err , [ ] , setError ) ;
23
+ } ;
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ type GetWeb3IdentifierParams = {
10
10
export async function getWeb3Identifier ( params : GetWeb3IdentifierParams ) : Promise < string > {
11
11
const { provider } = params ;
12
12
const ethereum = await getEthereumProvider ( provider ) ;
13
+
14
+ // TODO - core-3: Improve error handling for the case when the provider is not found
13
15
if ( ! ethereum ) {
14
16
// If a plugin for the requested provider is not found,
15
17
// the flow will fail as it has been the expected behavior so far.
@@ -28,6 +30,8 @@ type GenerateWeb3SignatureParams = GenerateSignatureParams & {
28
30
export async function generateWeb3Signature ( params : GenerateWeb3SignatureParams ) : Promise < string > {
29
31
const { identifier, nonce, provider } = params ;
30
32
const ethereum = await getEthereumProvider ( provider ) ;
33
+
34
+ // TODO - core-3: Improve error handling for the case when the provider is not found
31
35
if ( ! ethereum ) {
32
36
// If a plugin for the requested provider is not found,
33
37
// the flow will fail as it has been the expected behavior so far.
Original file line number Diff line number Diff line change @@ -582,6 +582,7 @@ export const enUS: LocalizationResource = {
582
582
passkey_pa_not_supported : 'Registration requires a platform authenticator but the device does not support it.' ,
583
583
passkey_registration_cancelled : 'Passkey registration was cancelled or timed out.' ,
584
584
passkey_retrieval_cancelled : 'Passkey verification was cancelled or timed out.' ,
585
+ web3_missing_identifier : 'A Web3 Wallet extension cannot be found. Please install one to continue.' ,
585
586
passwordComplexity : {
586
587
maximumLength : 'less than {{length}} characters' ,
587
588
minimumLength : '{{length}} or more characters' ,
Original file line number Diff line number Diff line change @@ -835,6 +835,7 @@ type UnstableErrors = WithParamName<{
835
835
passkey_retrieval_cancelled : LocalizationValue ;
836
836
passkey_registration_cancelled : LocalizationValue ;
837
837
passkey_already_exists : LocalizationValue ;
838
+ web3_missing_identifier : LocalizationValue ;
838
839
form_password_pwned : LocalizationValue ;
839
840
form_password_pwned__sign_in : LocalizationValue ;
840
841
form_username_invalid_length : LocalizationValue ;
You can’t perform that action at this time.
0 commit comments