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
53 lines (46 loc) · 1.35 KB
/
Copy pathauthorization-errors.ts
File metadata and controls
53 lines (46 loc) · 1.35 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
49
50
51
52
53
import type { __experimental_ReverificationConfig } from '@clerk/types';
type ClerkError<T> = {
clerk_error: T;
};
const REVERIFICATION_REASON = 'reverification-error';
type ReverificationError<M extends { metadata?: any } = { metadata: unknown }> = ClerkError<
{
type: 'forbidden';
reason: typeof REVERIFICATION_REASON;
} & M
>;
const __experimental_reverificationError = <MC extends __experimental_ReverificationConfig>(
missingConfig?: MC,
): ReverificationError<{
metadata: {
reverification?: MC;
};
}> => ({
clerk_error: {
type: 'forbidden',
reason: REVERIFICATION_REASON,
metadata: {
reverification: missingConfig,
},
},
});
const __experimental_reverificationErrorResponse = (...args: Parameters<typeof __experimental_reverificationError>) =>
new Response(JSON.stringify(__experimental_reverificationError(...args)), {
status: 403,
});
const __experimental_isReverificationHint = (
result: any,
): result is ReturnType<typeof __experimental_reverificationError> => {
return (
result &&
typeof result === 'object' &&
'clerk_error' in result &&
result.clerk_error?.type === 'forbidden' &&
result.clerk_error?.reason === REVERIFICATION_REASON
);
};
export {
__experimental_reverificationError,
__experimental_reverificationErrorResponse,
__experimental_isReverificationHint,
};