For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /api/angular-lynx/hardware/biometrics.md.

LynxBiometrics

Asks the person to confirm who they are with Face ID, Touch ID or a fingerprint. import { LynxBiometrics, BiometricsError, type BiometricsAvailability, type BiometricsAuthenticateOptions, type BiometricsErrorCode, type BiometryType } from '@blotch/angular-lynx';

To keep a secret, such as a refresh token, readable only after the person confirms, store it with LynxSecureStorage's requireBiometrics. The platform then won't hand it over without a face or a finger, which a check in your own code can't promise.

Turn it on

Add permissions.biometrics to the build target's options in angular.json, with the reason iOS shows the first time the app uses Face ID:

angular.json
"options": {
  "permissions": { "biometrics": "Unlock your notes" }
}

The reason is also the prompt's default text on both platforms.

What it adds:

  • iOS: NSFaceIDUsageDescription. Touch ID needs no reason, but Face ID fails without one.
  • Android: the USE_BIOMETRIC permission, granted at install, and the AndroidX Biometric library that shows the prompt.

It also turns on LynxSecureStorage's requireBiometrics.

Without it, ng build --platform leaves the module out of the app, and on Android AndroidX Biometric too. LynxBiometrics then behaves as in the web preview: availability() reports none, and authenticate() rejects with unavailable.

See Turn on device features for every setting.

Usage

const biometrics = inject(LynxBiometrics);

const { type, enrolled } = await biometrics.availability();
if (type !== 'none' && enrolled) {
  try {
    await biometrics.authenticate({ reason: 'Unlock your notes' });
    this.unlocked.set(true);
  } catch (error) {
    if (error instanceof BiometricsError && error.code === 'canceled') return;
    throw error;
  }
}

API

LynxBiometrics

@Injectable({ providedIn: 'root' })
class LynxBiometrics {}
  • iOS: LAContext.
  • Android: AndroidX's BiometricPrompt.
  • Elsewhere: only the apps ng build --platform makes with permissions.biometrics have it. In Lynx Explorer and the web preview, for example, availability() reports none and authenticate() rejects with unavailable.
  • The testing library stands for a phone with Face ID set up.

Android counts only strong (Class 3) biometrics, the ones that can unlock a Keystore key. That way authenticate() and the values kept behind biometrics agree on what confirms the person. A phone whose face unlock is weak reports its fingerprint sensor, or none.

LynxBiometrics.availability()

availability(): Promise<BiometricsAvailability>;

type BiometricsAvailability = {
  readonly type: BiometryType;
  readonly enrolled: boolean;
  readonly deviceCredential: boolean;
};

type BiometryType =
  | 'faceID'
  | 'touchID'
  | 'opticID'
  | 'fingerprint'
  | 'face'
  | 'iris'
  | 'none';

Never prompts or rejects.

FieldDescription
typeThe phone's sensor: faceID, touchID or opticID on Apple's devices, fingerprint, face or iris on Android, or none
enrolledWhether a face or a finger is set up, so authenticate() can ask for it. Still true while it's locked out after too many tries
deviceCredentialWhether the phone has a passcode, PIN or pattern, which allowDeviceCredential lets the person use instead

LynxBiometrics.authenticate()

authenticate(options: BiometricsAuthenticateOptions): Promise<void>;

type BiometricsAuthenticateOptions = {
  readonly reason: string;
  readonly allowDeviceCredential?: boolean;
  readonly title?: string;
  readonly cancelLabel?: string;
};

Shows the platform's prompt and resolves once the person is confirmed. Rejects with a BiometricsError, or a TypeError without a reason. One prompt can be open at a time.

OptionDescription
reasonWhy the app asks. Touch ID and Android's prompt show it; Face ID shows only its animation
allowDeviceCredentialLets the person use the passcode, PIN or pattern instead: iOS offers it after biometrics fail, Android on the prompt. Defaults to false
titleThe title of Android's prompt. Defaults to the app's name. iOS draws its own
cancelLabelThe label of the button that closes the prompt, Cancel by default. Android has none with allowDeviceCredential

BiometricsError

class BiometricsError extends Error {
  readonly code: BiometricsErrorCode;
}

type BiometricsErrorCode =
  'canceled' | 'lockout' | 'notEnrolled' | 'unavailable' | 'failed';
codeWhen
canceledThe person closed the prompt, or the system did, as when the app went to the background
lockoutToo many tries failed. iOS wants the passcode before biometrics work again; Android waits 30 seconds, or for the device credential
notEnrolledThe phone has a sensor, but no face or finger is set up
unavailableNo sensor, no passcode for allowDeviceCredential, or no biometrics module (no permissions.biometrics, Lynx Explorer, the web)
failedAnything else, such as a prompt already open