Skip to content

Commit 451aa80

Browse files
committed
chore: Export isReverificationCancelledError for all react related SDKs
1 parent 55cd4f9 commit 451aa80

File tree

11 files changed

+43
-25
lines changed

11 files changed

+43
-25
lines changed

.changeset/pretty-months-wonder.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@clerk/react-router': patch
3+
'@clerk/clerk-js': patch
4+
'@clerk/nextjs': patch
5+
'@clerk/clerk-react': patch
6+
'@clerk/remix': patch
7+
---
8+
9+
Export `isReverificationCancelledError` error helper

.changeset/tricky-deers-know.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,19 @@ This introducing changes to `useReverification`, the changes include removing th
77

88
```tsx {{ filename: 'src/components/MyButton.tsx' }}
99
import { useReverification } from '@clerk/clerk-react'
10-
import { isClerkRuntimeError } from '@clerk/clerk-react/error'
10+
import { isReverificationCancelledError } from '@clerk/clerk-react/error'
1111

1212
export function MyButton() {
1313
const enhancedFetcher = useReverification(() => fetch('/api/balance'))
1414

1515
const handleClick = async () => {
1616
try {
1717
const myData = await enhancedFetcher()
18-
// If `myData` is null, the user canceled the reverification process
19-
// You can choose how your app responds. This example returns null.
20-
if (!myData) return
2118
} catch (e) {
22-
// Handle error returned from the fetcher
19+
// Handle error returned from the fetcher here
2320

2421
// You can also handle cancellation with the following
25-
if (isClerkRuntimeError(err) && err.code === 'reverification_cancelled') {
22+
if (isReverificationCancelledError(err)) {
2623
// Handle the cancellation error here
2724
}
2825
}
@@ -37,8 +34,8 @@ to handle re-verification flow. When the handler is passed the default UI our AI
3734

3835

3936
```tsx {{ filename: 'src/components/MyButtonCustom.tsx' }}
40-
import { useReverification } from '@clerk/react'
41-
import { isClerkRuntimeError } from '@clerk/react/error'
37+
import { useReverification } from '@clerk/clerk-react'
38+
import { isReverificationCancelledError } from '@clerk/clerk-react/error'
4239

4340
export function MyButton() {
4441
const enhancedFetcher = useReverification(() => fetch('/api/balance'), {
@@ -50,11 +47,13 @@ export function MyButton() {
5047
const handleClick = async () => {
5148
try {
5249
const myData = await enhancedFetcher()
53-
// If `myData` is null, the user canceled the reverification process
54-
// You can choose how your app responds. This example returns null.
55-
if (!myData) return
5650
} catch (e) {
57-
// Handle error returned from the fetcher
51+
// Handle error returned from the fetcher here
52+
53+
// You can also handle cancellation with the following
54+
if (isReverificationCancelledError(err)) {
55+
// Handle the cancellation error here
56+
}
5857
}
5958
}
6059

packages/clerk-js/src/ui/components/UserProfile/ActiveDevicesSection.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,9 @@ const DeviceItem = ({ session }: { session: SessionWithActivitiesResource }) =>
6161
return;
6262
}
6363
status.setLoading();
64-
return (
65-
revokeSession()
66-
// TODO-STEPUP: Properly handler the response with a setCardError
67-
.catch(err => handleError(err, [], status.setError))
68-
.finally(() => status.setIdle())
69-
);
64+
return revokeSession()
65+
.catch(err => handleError(err, [], status.setError))
66+
.finally(() => status.setIdle());
7067
};
7168

7269
return (

packages/clerk-js/src/ui/components/UserProfile/MfaBackupCodeCreateForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isClerkRuntimeError } from '@clerk/shared/error';
1+
import { isReverificationCancelledError } from '@clerk/shared/error';
22
import { useReverification, useUser } from '@clerk/shared/react';
33
import type { BackupCodeResource } from '@clerk/types';
44
import React from 'react';
@@ -31,7 +31,7 @@ export const MfaBackupCodeCreateForm = withCardStateProvider((props: MfaBackupCo
3131
void createBackupCode()
3232
.then(backupCode => setBackupCode(backupCode))
3333
.catch(err => {
34-
if (isClerkRuntimeError(err) && err.code === 'reverification_cancelled') {
34+
if (isReverificationCancelledError(err)) {
3535
return onReset();
3636
}
3737

packages/nextjs/src/client-boundary/hooks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export {
1919
isEmailLinkError,
2020
isKnownError,
2121
isMetamaskError,
22+
isReverificationCancelledError,
2223
EmailLinkErrorCode,
2324
EmailLinkErrorCodeStatus,
2425
} from '@clerk/clerk-react/errors';

packages/nextjs/src/errors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export {
22
isClerkRuntimeError,
33
isEmailLinkError,
44
isKnownError,
5+
isReverificationCancelledError,
56
isMetamaskError,
67
EmailLinkErrorCode,
78
EmailLinkErrorCodeStatus,

packages/react-router/src/errors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export {
33
isEmailLinkError,
44
isKnownError,
55
isMetamaskError,
6+
isReverificationCancelledError,
67
EmailLinkErrorCode,
78
EmailLinkErrorCodeStatus,
89
} from '@clerk/clerk-react/errors';

packages/react/src/errors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export {
44
isEmailLinkError,
55
isKnownError,
66
isMetamaskError,
7+
isReverificationCancelledError,
78
EmailLinkErrorCode,
89
EmailLinkErrorCodeStatus,
910
} from '@clerk/shared/error';

packages/remix/src/errors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export {
33
isEmailLinkError,
44
isKnownError,
55
isMetamaskError,
6+
isReverificationCancelledError,
67
EmailLinkErrorCode,
78
EmailLinkErrorCodeStatus,
89
} from '@clerk/clerk-react/errors';

packages/shared/src/react/hooks/useReverification.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,22 @@ function createReverificationHandler(params: CreateReverificationHandlerParams)
161161
*
162162
* ```tsx {{ filename: 'src/components/MyButton.tsx' }}
163163
* import { useReverification } from '@clerk/clerk-react'
164+
* import { isReverificationCancelledError } from '@clerk/clerk-react/error'
164165
*
165166
* export function MyButton() {
166-
* const enhancedFetcher = useReverification(myFetcher)
167+
* const enhancedFetcher = useReverification(() => fetch('/api/balance'))
167168
*
168169
* const handleClick = async () => {
169-
* const myData = await enhancedFetcher()
170-
* // If `myData` is null, the user canceled the reverification process
171-
* // You can choose how your app responds. This example returns null.
172-
* if (!myData) return
170+
* try {
171+
* const myData = await enhancedFetcher()
172+
* } catch (e) {
173+
* // Handle error returned from the fetcher here
174+
*
175+
* // You can also handle cancellation with the following
176+
* if (isReverificationCancelledError(err)) {
177+
* // Handle the cancellation error here
178+
* }
179+
* }
173180
* }
174181
*
175182
* return <button onClick={handleClick}>Update User</button>

0 commit comments

Comments
 (0)