Passkeys use cryptographic key pairs stored on the user’s device. Authentication happens with a biometric check (such as Face ID, Touch ID, or a fingerprint scan)
or a local device PIN. This makes passkeys both safer—since they can’t be phished or reused—and easier to use, since users don’t need to remember or type credentials.
Prerequisites
You need to have the Dynamic Client initialized.
You need to have the passkey MFA enabled in your environment’s settings in the Dynamic Console.
Registering a new passkey
Calling registerPasskey will prompt the user to register a new passkey in their device and register it in the Dynamic server,
so next time the user can complete an MFA challenge with it or even sign-in with it if enabled in the environment’s settings.Registering a passkey will automatically authenticate it, so you don’t need to call authenticatePasskeyMFA after registering a passkey.
Calling authenticatePasskeyMFA will prompt the user to authenticate with a passkey in their device and complete an MFA challenge.
The authentication will be successful if the user authenticates with the passkey in their device and it gets validated in the Dynamic server.
To authenticate with a passkey that was registered on a related domain, pass that domain as relatedOriginRpId. This lets users complete MFA with passkeys they created before your domain changed. See Signing in with a passkey from a related domain for the required .well-known/webauthn setup on the related domain.
import { authenticatePasskeyMFA } from '@dynamic-labs-sdk/client';await authenticatePasskeyMFA({ relatedOriginRpId: 'old.example.com' });
Calling deletePasskey will delete a passkey from the Dynamic server.
import { deletePasskey } from '@dynamic-labs-sdk/client';const handleDeletePasskey = async () => { // Replace 'passkey-id' with the actual ID of the passkey you want to delete await deletePasskey({passkeyId: 'passkey-id'});};
Getting all registered passkeys for a user
Calling getPasskeys will return all registered passkeys for the authenticated user.
useGetPasskeys fetches the list. Mutations like useRegisterPasskey and useDeletePasskey automatically refetch the passkey list on success, so the UI stays in sync without manual intervention: