forked from clerk/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthorization-errors.ts
More file actions
48 lines (42 loc) · 1.31 KB
/
Copy pathauthorization-errors.ts
File metadata and controls
48 lines (42 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import type { __experimental_ReverificationConfig } from '@clerk/types';
type ClerkError<T> = {
clerk_error: T;
};
type ReverificationMismatchError<M extends { metadata?: any } = { metadata: unknown }> = ClerkError<
{
type: 'forbidden';
reason: 'reverification-mismatch';
} & M
>;
const __experimental_reverificationMismatch = <MC extends __experimental_ReverificationConfig>(missingConfig?: MC) =>
({
clerk_error: {
type: 'forbidden',
reason: 'reverification-mismatch',
metadata: {
reverification: missingConfig,
},
},
}) satisfies ReverificationMismatchError;
const __experimental_reverificationMismatchResponse = (
...args: Parameters<typeof __experimental_reverificationMismatch>
) =>
new Response(JSON.stringify(__experimental_reverificationMismatch(...args)), {
status: 403,
});
const __experimental_isReverificationHint = (
result: any,
): result is ReturnType<typeof __experimental_reverificationMismatch> => {
return (
result &&
typeof result === 'object' &&
'clerk_error' in result &&
result.clerk_error?.type === 'forbidden' &&
result.clerk_error?.reason === 'reverification-mismatch'
);
};
export {
__experimental_reverificationMismatch,
__experimental_reverificationMismatchResponse,
__experimental_isReverificationHint,
};