expo-passkey
Version:
Passkey authentication for Expo apps with Better Auth integration
103 lines • 4.76 kB
JavaScript
/**
* @file Error type definitions and constants
* @module expo-passkey/types/errors
*/
/**
* Error codes for the Expo Passkey plugin
*/
export const ERROR_CODES = {
// Client-side error codes
ENVIRONMENT: {
NOT_SUPPORTED: "environment_not_supported",
MODULE_NOT_FOUND: "module_not_found",
},
BIOMETRIC: {
NOT_SUPPORTED: "biometric_not_supported",
NOT_ENROLLED: "biometric_not_enrolled",
AUTHENTICATION_FAILED: "biometric_authentication_failed",
},
DEVICE: {
ID_GENERATION_FAILED: "device_id_generation_failed",
},
NETWORK: {
REQUEST_FAILED: "network_request_failed",
},
WEBAUTHN: {
NOT_SUPPORTED: "webauthn_not_supported",
CANCELED: "webauthn_canceled",
TIMEOUT: "webauthn_timeout",
OPERATION_FAILED: "webauthn_operation_failed",
INVALID_STATE: "webauthn_invalid_state",
CHALLENGE_EXPIRED: "webauthn_challenge_expired",
INVALID_RESPONSE: "webauthn_invalid_response",
NOT_SECURE_CONTEXT: "webauthn_not_secure_context",
INVALID_CREDENTIAL: "webauthn_invalid_credential",
NATIVE_MODULE_ERROR: "webauthn_native_module_error",
},
// Server-side error codes
SERVER: {
CREDENTIAL_EXISTS: "device_already_registered",
INVALID_CREDENTIAL: "invalid_credential",
CREDENTIAL_NOT_FOUND: "credential_not_found",
REGISTRATION_FAILED: "registration_failed",
AUTHENTICATION_FAILED: "authentication_failed",
REVOCATION_FAILED: "revocation_failed",
INVALID_ORIGIN: "invalid_origin",
INVALID_CLIENT: "invalid_client",
PASSKEYS_RETRIEVAL_FAILED: "passkeys_retrieval_failed",
USER_NOT_FOUND: "user_not_found",
CHALLENGE_GENERATION_FAILED: "challenge_generation_failed",
INVALID_CHALLENGE: "invalid_challenge",
EXPIRED_CHALLENGE: "expired_challenge",
VERIFICATION_FAILED: "verification_failed",
},
};
/**
* Error messages mapped to error codes
*/
export const ERROR_MESSAGES = {
[]: "Environment not supported",
[]: "Required module not found",
[]: "Biometric authentication not supported on this device",
[]: "Biometric authentication not enrolled on this device",
[]: "Biometric authentication failed",
[]: "Failed to generate device ID",
[]: "Network request failed",
[]: "WebAuthn is not supported on this device",
[]: "WebAuthn operation was canceled by the user",
[]: "WebAuthn operation timed out",
[]: "WebAuthn operation failed",
[]: "WebAuthn is in an invalid state",
[]: "WebAuthn challenge has expired",
[]: "Invalid WebAuthn response",
[]: "WebAuthn requires a secure context (HTTPS)",
[]: "Invalid WebAuthn credential",
[]: "Error in WebAuthn native module",
[]: "Device already registered",
[]: "Invalid credential",
[]: "Credential not found",
[]: "Failed to register device",
[]: "Authentication failed",
[]: "Failed to revoke credential",
[]: "Invalid origin",
[]: "Invalid client",
[]: "Failed to retrieve passkeys",
[]: "User not found",
[]: "Failed to generate challenge",
[]: "Invalid challenge",
[]: "Challenge has expired",
[]: "WebAuthn verification failed",
};
/**
* Custom error class for passkey errors
*/
export class PasskeyError extends Error {
constructor(code, message) {
super(message ||
ERROR_MESSAGES[code] ||
"Unknown error");
this.name = "PasskeyError";
this.code = code;
}
}
//# sourceMappingURL=errors.js.map