Biometric login

Prompt for Face ID, Touch ID, or fingerprint and read the result.

Prompt for biometric auth

Use biometrics as a local confirmation before a sensitive UI step. It is not payment authorization or proof of identity to your backend; scripts on the page can imitate a client-side result.

Examples reuse the single browser client from Set up the client. Adjust the ~/lib/bdk import to your app’s path; do not create a client in each component or handler.

Pass an optional reason string to show in the prompt.

A biometric result is local; never send it to a server as proof. Use your backend’s normal authentication and authorization.

Check getDeviceInfo()?.biometricsAvailable before prompting, and fall back to PIN/password when it's false. Wrap the call in try/catch.

Awaiting the call only confirms the prompt was requested. The actual success or failure arrives on the biometricResult event.

import { bdk } from "~/lib/bdk";

await bdk.ready(3000);
try {
  await bdk.auth.authenticateBiometrics();
} catch {
}

Read the result

Subscribe to biometricResult to learn whether auth succeeded. The BiometricResult payload has status ("success" or "failed"), data (the raw native auth result), and platform ("ios" | "android"). bdk.on(...) returns an unsubscribe function — call it when you're done.

A failed or cancelled prompt comes through biometricResult, not the error event, and does not reject the promise. Branch on status inside your listener.

const off = bdk.on("biometricResult", ({ data, status, platform }) => {
  if (status === "success") {
    console.log(`Authenticated on ${platform}`, data);
    // Reveal local UI only; server authorization is separate.
  } else {
    console.warn("Biometric auth did not succeed:", status, data);
  }
});

// Later, when you're done listening:
off();

Subscribe before you prompt

Register the biometricResult listener before calling authenticateBiometrics(), or a fast result can be missed.

Wait for device info before this call. On failure or timeout, offer your normal sign-in path; keep payment and session authorization on the backend.

import { bdk } from "~/lib/bdk";

async function confirmWithBiometrics(timeoutMs = 60000): Promise<boolean> {
  const info = await bdk.ready(3000);
  if (!info?.biometricsAvailable) return false;
  return new Promise((resolve) => {
    let settled = false;
    let off: () => void = () => {};
    const finish = (ok: boolean) => {
      if (settled) return;
      settled = true;
      clearTimeout(timer);
      off();
      resolve(ok);
    };
    const timer = setTimeout(() => finish(false), timeoutMs);
    off = bdk.on("biometricResult", ({ status }) => finish(status === "success"));
    void bdk.auth.authenticateBiometrics().then((result) => {
      if (!result.triggered) finish(false);
    }).catch(() => finish(false));
  });
}

See it running in the live demo, or every native feature with its demo on thebdk.com.