Skip to main content
‹ Errors
Constants

KeychainErrorCode

Why a call failed: twenty codes, the same on iOS and Android. A constant object and a type of the same name: KeychainErrorCode.KeyInvalidated is the string KEY_INVALIDATED.

Import
import { KeychainErrorCode } from '@apexnative/keychain';

The code of a KeychainError. Each constant is its string, so error.code === KeychainErrorCode.KeyInvalidated and error.code === 'KEY_INVALIDATED' are the same check, and a switch over the constants is checked by TypeScript.

Usage​

import { KeychainError, KeychainErrorCode } from '@apexnative/keychain';

function message(error: KeychainError): string | null {
switch (error.code) {
case KeychainErrorCode.UserCanceled:
case KeychainErrorCode.SystemCanceled:
return null;
case KeychainErrorCode.Lockout:
return 'Too many attempts. Try again in a moment.';
case KeychainErrorCode.KeyInvalidated:
return 'Face ID changed on this device. Sign in again.';
default:
return 'Something went wrong.';
}
}

Signature​

const KeychainErrorCode: {
readonly UserCanceled: 'USER_CANCELED';
readonly UserFallback: 'USER_FALLBACK';
// … one member for each code below
readonly Unknown: 'UNKNOWN';
};

type KeychainErrorCode = (typeof KeychainErrorCode)[keyof typeof KeychainErrorCode];
Type'USER_CANCELED' | 'USER_FALLBACK' | … | 'UNKNOWN'PlatformsiOSAndroid

Codes​

The prompt​

ConstantStringWhen
UserCanceledUSER_CANCELEDThe user canceled the prompt. On Android 16, also a prompt that was open when the app went to the background: Android reports it as the user's cancel
UserFallbackUSER_FALLBACKiOS: the user tapped the fallback button of a prompt for biometrics alone (biometryAny, biometryCurrentSet). prompt.fallback: '' hides the button
SystemCanceledSYSTEM_CANCELEDThe system closed the prompt: the app went to the background, a call came in
AuthFailedAUTH_FAILEDiOS: the face or the finger wasn't recognized
LockoutLOCKOUTToo many failed attempts: the biometrics is locked for a while
LockoutPermanentLOCKOUT_PERMANENTAndroid: the biometrics is locked until the user enters the passcode

The device​

ConstantStringWhen
BiometryNotEnrolledBIOMETRY_NOT_ENROLLEDA write that needs enrolled biometrics, on a device without
BiometryNotAvailableBIOMETRY_NOT_AVAILABLEA write that needs biometrics, on a device without a sensor, or with one that is unavailable
PasscodeNotSetPASSCODE_NOT_SETA write that needs a passcode, PIN or pattern, on a device without
HardwareUnavailableHARDWARE_UNAVAILABLEAndroid: strongboxRequired on a device without StrongBox
UnsupportedUNSUPPORTEDThe option needs a newer OS (the passcode or authValidity before Android 11), the platform has no keychain (the web), or the native module isn't in the app (Expo Go)

The item​

ConstantStringWhen
KeyInvalidatedKEY_INVALIDATEDThe enrolled biometrics changed since a biometryCurrentSet* item was written: the item was removed. Sign the user in again
DataCorruptedDATA_CORRUPTEDThe stored value can't be decrypted or decoded, and not because the key was invalidated

Not now​

ConstantStringWhen
InteractionNotAllowedINTERACTION_NOT_ALLOWEDThe device is locked, and the item is whenUnlocked* or whenPasscodeSetThisDeviceOnly; on iOS also a prompt asked for in the background
AuthRequiredAUTH_REQUIREDA synchronous read of an item that needs a prompt
NoActivityNO_ACTIVITYAndroid: no activity to show the prompt in

The app's setup​

ConstantStringWhen
MissingEntitlementMISSING_ENTITLEMENTiOS: an accessGroup the app has no entitlement for
MissingUsageDescriptionMISSING_USAGE_DESCRIPTIONiOS: NSFaceIDUsageDescription is missing from Info.plist, on a device with Face ID; for a biometric item's write and read, and for canUseAccessControl
InvalidArgumentINVALID_ARGUMENTA key, a value or options that aren't valid; bytes read as text that aren't UTF-8; on iOS, a key held by another library's item

Anything else​

ConstantStringWhen
UnknownUNKNOWNA failure the package has no code for; nativeCode and nativeDomain say more

See also​