Testing for browser passkey support
Most devices and browsers now support passkeys, albeit with a few quirks. Nevertheless, don’t assume support is universal.
isPasskeySupport
Section titled “isPasskeySupport”Before prompting the user to register or authenticate with a passkey you should call isPasskeySupport().
import { isPasskeySupport } from "@passlock/browser";
if (!isPasskeySupport()) { throw new Error("Bad news...")}PasskeyUnsupported error
Section titled “PasskeyUnsupported error”Alternatively test for the PasskeyUnsupportedError:
import { Passlock, isPasskeyUnsupportedError } from "@passlock/browser";
const passlock = new Passlock({ tenancyId });const result = await passlock.registerPasskey(options)
if (result.success) { // happy days} else if (isPasskeyUnsupportedError(result.error)) { // no passkey support on this device} else { console.error(result.error.message);}import { Passlock, isPasskeyUnsupportedError } from "@passlock/browser/unsafe";
const passlock = new Passlock({ tenancyId });
try { const result = await passlock.registerPasskey(options)} catch (e) { if (isPasskeyUnsupportedError(e)) { // no passkey support on this device }}import { registerPasskey, isPasskeyUnsupportedError} from "@passlock/browser";
const result = await registerPasskey(options, { tenancyId })
if (result.success) { // happy days} else if (isPasskeyUnsupportedError(result.error)) { // no passkey support on this device} else { console.error(result.error.message);}import { registerPasskey, isPasskeyUnsupportedError } from "@passlock/browser/unsafe";
try { const result = await registerPasskey(options, { tenancyId })} catch (e) { if (isPasskeyUnsupportedError(e)) { // no passkey support on this device }}
Choose your code style
Other capability checks
Section titled “Other capability checks”Passlock also exposes capability checks for newer WebAuthn signal APIs. These are useful for features such as device-local passkey deletion, updates, and pruning:
import { isPasskeyDeleteSupport, isPasskeyPruningSupport, isPasskeyUpdateSupport,} from "@passlock/browser";
if (!isPasskeyDeleteSupport()) { console.log("Local passkey deletion is unavailable on this device");}
if (!isPasskeyUpdateSupport()) { console.log("Local passkey updates are unavailable on this device");}
if (!isPasskeyPruningSupport()) { console.log("Local passkey pruning is unavailable on this device");}