Passkey authentication
The authentication section of the quick start guide covers the basics, so we’ll focus on some more advanced aspects of passkey authentication here.
Testing for passkey support
Section titled “Testing for passkey support”Similar to the registration flow, you probably want to test for passkey support:
import { isPasskeySupport } from "@passlock/browser";
if (!isPasskeySupport()) { throw new Error("Bad news...")}Biometric verification
Section titled “Biometric verification”User verification is especially useful during authentication:
import { authenticatePasskey } from "@passlock/browser";
// discouraged, preferred (default) or requiredconst userVerification = "required" as const;const result = await authenticatePasskey({ tenancyId, userVerification });Pre-selecting a passkey
Section titled “Pre-selecting a passkey”To preselect the passkey(s) presented to the user, pass the ids via the allowCredentials option:
import { authenticatePasskey } from "@passlock/browser";
const allowCredentials = [existingPasskeyId]const result = await authenticatePasskey({ allowCredentials, ... })This is conceptually similar to the excludeCredentials registration option.
Autofill
Section titled “Autofill”If you support more than one login mechanism, passkey autofill tells the browser to use passkey login if a passkey exists on the device.
import { authenticatePasskey } from "@passlock/browser";
document.addEventListener('DOMContentLoaded', async () => { const result = await authenticatePasskey({ autofill: true, ... });})Two-step login
Section titled “Two-step login”Alternatively, you might choose to implement a two-step login flow, in which the user first enters their account identifier (username/email), before authenticating using their chosen mechanism. After they enter their identifier, check if they registered a passkey, and if so prompt them to authenticate with it.
Handling missing passkeys
Section titled “Handling missing passkeys”Passkeys are comprised of two components - a private key, stored on the user’s device, and a public key, stored in your Passlock vault. If either component is missing the user will receive an error. Learn how to handle missing passkeys gracefully.