Skip to content
Get started
Bastionary › Knowledge base › MFA and passkeys

WebAuthn conditional UI: passkey autofill that users actually notice

By Bastionary · MFA and passkeys

Most passkey sign-in flows still make the user do work: click a "Sign in with a passkey" button, wait for a modal, pick a credential. It functions, but it announces itself. Conditional UI (also called conditional mediation, or passkey autofill) removes that ceremony entirely. The passkey surfaces as an autofill suggestion right inside the username field, the same place the browser already offers saved passwords, so signing in feels like nothing happened at all.

The effect is subtle and that is the point. A returning user taps the email field, sees their account offered, taps it, completes the platform's biometric check, and is in. No button, no detour, no decision about which method to use. Done well, conditional UI is the flow that finally makes passkeys feel faster than passwords instead of merely safer.

Conditional mediation versus the modal flow

A standard passkey login calls navigator.credentials.get() with mediation: "required" or the default, which pops the browser's account chooser immediately. Conditional UI uses mediation: "conditional", which does the opposite: the call starts silently, waits in the background, and only offers credentials when the user focuses an input you have tagged as a WebAuthn target. If the user would rather type a password, nothing interrupts them.

The two pieces that make it work are the autocomplete token on the field and the long-lived get() call behind it.

The HTML is half the job

The browser only knows a field can accept a passkey because you tell it, by adding webauthn to the autocomplete attribute. Without this token, conditional mediation never fires.

<form id="login">
  <label for="email">Email</label>
  <input
    id="email"
    name="email"
    type="email"
    autocomplete="username webauthn"
    autofocus>
  <button type="submit">Continue</button>
</form>

Note it is username webauthn, not webauthn alone. You are telling the browser this is the username field and that passkeys are welcome here. On a password field you would use current-password webauthn.

Starting the conditional request

On page load, first check that conditional mediation is even available, then fire a get() that will quietly resolve when the user picks a suggestion. Crucially, you start this request yourself at load time; the browser does the waiting.

async function startConditionalLogin() {
  // Feature-detect: not all browsers support conditional mediation.
  if (!window.PublicKeyCredential?.isConditionalMediationAvailable) return;
  if (!(await PublicKeyCredential.isConditionalMediationAvailable())) return;

  // Fetch a fresh challenge from your server.
  const options = await fetch("/webauthn/login/options").then(r => r.json());

  try {
    const assertion = await navigator.credentials.get({
      mediation: "conditional",            // the key line
      publicKey: {
        challenge: base64urlToBuffer(options.challenge),
        rpId: options.rpId,
        userVerification: "preferred",
        // no allowCredentials: discoverable credentials drive the autofill list
      },
      signal: loginAbortController.signal, // so we can cancel it later
    });
    await postAssertion(assertion); // verify server-side, establish session
  } catch (err) {
    if (err.name !== "AbortError") console.error(err);
  }
}

document.addEventListener("DOMContentLoaded", startConditionalLogin);

Two details decide whether this works. You omit allowCredentials, because conditional UI relies on discoverable credentials (resident keys) that the authenticator can enumerate without being told which to look for. And you hold an AbortController, because you will need to cancel this pending request the moment the user chooses a different path.

Discoverable credentials are mandatory here. If your registration flow created non-discoverable credentials to save authenticator storage, they will never appear in autofill. Set residentKey: "required" (or at least "preferred") during registration or conditional UI silently shows nothing.

Managing the lifecycle without stray requests

A conditional get() stays pending, sometimes for the whole time the page is open. You cannot have two outstanding WebAuthn requests at once, so if the user clicks an explicit "Sign in with passkey" button, or submits a password, you must abort the conditional request first.

const loginAbortController = new AbortController();

// User chose the explicit modal flow instead.
async function explicitPasskeyLogin() {
  loginAbortController.abort();              // cancel the conditional request
  const fresh = new AbortController();
  const options = await fetch("/webauthn/login/options").then(r => r.json());
  await navigator.credentials.get({
    mediation: "required",
    signal: fresh.signal,
    publicKey: { /* ... */ },
  });
}

Gotcha: forgetting to abort leaves a zombie conditional request that throws NotAllowedError the instant you start a second one. Every entry point to authentication on that page must share, and honor, the same abort controller.

Server verification does not change

Conditional UI is purely a client-side mediation hint. The assertion you receive is an ordinary WebAuthn assertion, and your server verifies it exactly as it would from the modal flow: confirm the challenge matches what you issued, verify the signature against the stored public key, check the RP ID hash and origin, and enforce the signature counter if the authenticator provides one. Do not relax any of that because the credential arrived through autofill; the mediation mode is a UX choice, not a trust signal.

Graceful degradation

Not every browser and platform supports conditional mediation, and support shifts over time, so design the page to stand on its own. Keep the username field and password fallback fully functional, and treat autofill as progressive enhancement. If isConditionalMediationAvailable() returns false, the user simply sees a normal login form; nothing breaks, and an explicit passkey button can still cover them.

  • Always feature-detect before calling; never assume support.
  • Keep a visible, explicit passkey option for discoverability and for unsupported browsers.
  • Make sure the password path still works for users who have not enrolled a passkey yet.

Why the polish is worth it

Conditional UI is the detail that separates a passkey rollout users tolerate from one they prefer. When the credential is simply there in the field they already tapped, friction drops below what a password ever offered, and that is what finally moves adoption numbers. Building it means owning the registration side too, since discoverable credentials are a decision you make at enrollment. Running your own identity layer lets you tune both ends of that flow together instead of hoping a hosted widget exposed the right knobs. For the full registration and assertion endpoints, see the developer docs.

Run it yourself

Bastionary is free, open-source software. Follow the quick start to have it running on your own server, or browse the releases on Git.

Get started