-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathWebAuthError.ts
More file actions
57 lines (49 loc) · 1.84 KB
/
WebAuthError.ts
File metadata and controls
57 lines (49 loc) · 1.84 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
import { AuthError } from './AuthError';
const ERROR_CODE_MAP: Record<string, string> = {
// --- Common Codes ---
'a0.session.user_cancelled': 'USER_CANCELLED',
'USER_CANCELLED': 'USER_CANCELLED',
'access_denied': 'ACCESS_DENIED',
'a0.network_error': 'NETWORK_ERROR',
'a0.session.invalid_idtoken': 'ID_TOKEN_VALIDATION_FAILED',
'ID_TOKEN_VALIDATION_FAILED': 'ID_TOKEN_VALIDATION_FAILED',
'BIOMETRICS_CONFIGURATION_ERROR': 'BIOMETRICS_CONFIGURATION_ERROR',
// --- Android-specific mappings ---
'a0.browser_not_available': 'BROWSER_NOT_AVAILABLE',
'a0.session.failed_load': 'FAILED_TO_LOAD_URL',
'a0.session.browser_terminated': 'BROWSER_TERMINATED',
// --- iOS-specific mappings ---
'NO_BUNDLE_IDENTIFIER': 'NO_BUNDLE_IDENTIFIER',
'TRANSACTION_ACTIVE_ALREADY': 'TRANSACTION_ACTIVE_ALREADY',
'NO_AUTHORIZATION_CODE': 'NO_AUTHORIZATION_CODE',
'PKCE_NOT_ALLOWED': 'PKCE_NOT_ALLOWED',
'INVALID_INVITATION_URL': 'INVALID_INVITATION_URL',
// --- Web (@auth0/auth0-spa-js) mappings ---
'cancelled': 'USER_CANCELLED',
'state_mismatch': 'INVALID_STATE',
'login_required': 'ACCESS_DENIED',
'timeout': 'TIMEOUT_ERROR',
'consent_required': 'CONSENT_REQUIRED',
// --- Generic Fallbacks ---
'a0.invalid_configuration': 'INVALID_CONFIGURATION',
'UNKNOWN': 'UNKNOWN_ERROR',
'OTHER': 'UNKNOWN_ERROR',
};
export class WebAuthError extends AuthError {
public readonly type: string;
constructor(originalError: AuthError) {
super(originalError.name, originalError.message, {
status: originalError.status,
code: originalError.code,
json: originalError.json,
});
if (
originalError.message.includes('state is invalid') ||
originalError.code === 'state_mismatch'
) {
this.type = 'INVALID_STATE';
} else {
this.type = ERROR_CODE_MAP[originalError.code] || 'UNKNOWN_ERROR';
}
}
}