-
Notifications
You must be signed in to change notification settings - Fork 442
Expand file tree
/
Copy patherrors.ts
More file actions
73 lines (61 loc) · 2.5 KB
/
errors.ts
File metadata and controls
73 lines (61 loc) · 2.5 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
export type TokenCarrier = 'header' | 'cookie';
export const TokenVerificationErrorCode = {
InvalidSecretKey: 'clerk_key_invalid',
};
export type TokenVerificationErrorCode = (typeof TokenVerificationErrorCode)[keyof typeof TokenVerificationErrorCode];
export const TokenVerificationErrorReason = {
TokenExpired: 'token-expired',
TokenInvalid: 'token-invalid',
TokenInvalidAlgorithm: 'token-invalid-algorithm',
TokenInvalidAuthorizedParties: 'token-invalid-authorized-parties',
TokenInvalidSignature: 'token-invalid-signature',
TokenNotActiveYet: 'token-not-active-yet',
TokenIatInTheFuture: 'token-iat-in-the-future',
TokenVerificationFailed: 'token-verification-failed',
InvalidSecretKey: 'secret-key-invalid',
LocalJWKMissing: 'jwk-local-missing',
RemoteJWKFailedToLoad: 'jwk-remote-failed-to-load',
RemoteJWKInvalid: 'jwk-remote-invalid',
RemoteJWKMissing: 'jwk-remote-missing',
JWKFailedToResolve: 'jwk-failed-to-resolve',
JWKKidMismatch: 'jwk-kid-mismatch',
MachineTokenUsedForUserRequest: 'machine-token-used-for-user-request',
UserTokenUsedForMachineRequest: 'user-token-used-for-machine-request',
};
export type TokenVerificationErrorReason =
(typeof TokenVerificationErrorReason)[keyof typeof TokenVerificationErrorReason];
export const TokenVerificationErrorAction = {
ContactSupport: 'Contact support@clerk.com',
EnsureClerkJWT: 'Make sure that this is a valid Clerk generate JWT.',
SetClerkJWTKey: 'Set the CLERK_JWT_KEY environment variable.',
SetClerkSecretKey: 'Set the CLERK_SECRET_KEY environment variable.',
EnsureClockSync: 'Make sure your system clock is in sync (e.g. turn off and on automatic time synchronization).',
};
export type TokenVerificationErrorAction =
(typeof TokenVerificationErrorAction)[keyof typeof TokenVerificationErrorAction];
export class TokenVerificationError extends Error {
action?: TokenVerificationErrorAction;
reason: TokenVerificationErrorReason;
tokenCarrier?: TokenCarrier;
constructor({
action,
message,
reason,
}: {
action?: TokenVerificationErrorAction;
message: string;
reason: TokenVerificationErrorReason;
}) {
super(message);
Object.setPrototypeOf(this, TokenVerificationError.prototype);
this.reason = reason;
this.message = message;
this.action = action;
}
public getFullMessage() {
return `${[this.message, this.action].filter(m => m).join(' ')} (reason=${this.reason}, token-carrier=${
this.tokenCarrier
})`;
}
}
export class SignJWTError extends Error {}