const cred = await navigator.credentials.get({
publicKey: {
challenge: crypto.getRandomValues(new Uint8Array(32)),
},
});const { challenge } = await fetch('/auth/challenge').then((r) => r.json());
const cred = await navigator.credentials.get({
publicKey: { challenge: base64urlToBuffer(challenge) },
});
await sendToServerForVerification(cred);The challenge comes from the server and is checked there once, so a captured response cannot be replayed.
autocomplete='username webauthn' for passkey autofill.Yes. The private key never leaves the authenticator and is bound to the site's domain, so passkeys cannot be phished, reused or leaked in a server breach.
Passkeys synced by a password manager come back on a new device. Otherwise the user signs in with another registered passkey or the site's recovery method.
Yes. Browsers treat localhost as a secure context, so WebAuthn works there, while other origins need HTTPS.