Passkeys
Your users can sign in with a passkey and confirm it with their device’s PIN, fingerprint or face. A user signs in another way first and creates a passkey, then uses it to sign in on later visits.
Turn on passkeys
To turn on passkeys, add passkey with "enabled": true to plugins in the auth block of amplify.jsonc, next to your other auth settings. The passkey calls in the client SDK return an error until you turn passkeys on. For how the auth block works and how to apply your changes, see Auth configuration.
// amplify.jsonc { "backend": { "auth": { "appName": "Acme Notes", "emailAndPassword": { "enabled": true }, "plugins": { "passkey": { "enabled": true } } } } }
Your users see your appName as the passkey’s site name when they create and use a passkey. When passkeys are on, the managed sign-in page has a passkey sign-in option, if the page’s host is under the rpId and its origin is one of the passkey origins.
Add a passkey
To let a signed-in user create a passkey, call passkey.addPasskey.
const { data, error } = await backend.auth.passkey.addPasskey({ name: 'Work laptop', // optional; a name for the passkey authenticatorAttachment: 'platform', // optional; 'platform' for the user's device, 'cross-platform' for a security key })
Users of the managed sign-in page also create their passkeys in your app, with passkey.addPasskey.
To show and manage a signed-in user’s passkeys, call the following:
-
passkey.listUserPasskeys()– Returns the user’s passkeys. -
passkey.updatePasskey({ id, name })– Renames a passkey. -
passkey.deletePasskey({ id })– Deletes a passkey.
When a user whose address isn’t verified signs in with an email link or an email code for the first time, the backend deletes the user’s passkeys. To keep a user’s passkeys, have them verify their email address before they create one. For more information, see Passwordless sign-in.
Sign users in with a passkey
To sign a user in with a passkey, call signIn.passkey.
Browser code gets AMPLIFY_BACKEND_URL and AMPLIFY_BACKEND_PUBLISHABLE_KEY only when your framework inlines them as your app builds, such as with a Vite define. For more information, see the client SDK README
import { createClient } from '@aws-amplifygen3/backend-client-js' const backend = createClient(import.meta.env.AMPLIFY_BACKEND_URL, import.meta.env.AMPLIFY_BACKEND_PUBLISHABLE_KEY) const { data, error } = await backend.auth.signIn.passkey({ autoFill, // optional })
On success, data.session holds the user’s session.
When the device doesn’t check the user’s PIN, fingerprint or face, the backend refuses to create the passkey or to sign the user in, with PASSKEY_USER_VERIFICATION_REQUIRED. To show a passkey button only when passkeys are on, check the sign-in methods that auth.getMethods() returns.
Set the passkey domain and origins
A passkey belongs to one domain, the relying party ID (rpId), and works on that domain and its subdomains. Users can create and use passkeys only on the passkey origins. By default, the passkey origins are your trustedOrigins entries without a *, or, when you have no such entries, the origin that the browser calls the backend on. The default rpId is that origin’s host. On the local backend, the passkey origins also include the dev servers that aws amplifygen3 local run trusts on the rpId host. Your Amplify app URL and custom domains aren’t passkey origins unless you list them in trustedOrigins or origins, even though Amplify trusts them for redirects. A deployment with two exact trustedOrigins entries on different hosts and no rpId fails, even when passkeys run on one host only.
When your app runs on more than one host, set rpId to their shared parent domain, and list up to 5 exact origins in origins.
// amplify.jsonc { "backend": { "auth": { "appName": "Acme Notes", "emailAndPassword": { "enabled": true }, "plugins": { "passkey": { "enabled": true, "rpId": "example.com", "origins": ["https://app.example.com", "https://www.example.com"] } } } } }
Passkeys work only on exact origins. A deployment fails with CONFIG_RETRIEVAL_FAILED when origins has a wildcard over hosts that others own, such as https://*.vercel.app.
Settings
Set these in plugins.passkey in the auth block.
| Setting | Values | Default |
|---|---|---|
|
|
|
|
|
|
A host with no scheme or port, 1 to 253 characters of letters, digits, |
The host of the one origin |
|
|
Up to 5 exact origins, each a scheme, host and port |
Your |
Errors
The client SDK returns each error’s code in error.code.
| Code | When | What to do |
|---|---|---|
|
|
The device created or used a passkey without the user’s PIN, fingerprint or face |
Show the error’s message and offer password sign-in. Don’t retry |
|
|
With no |
Set |
|
|
A deployment where |
List each origin exactly |
|
|
The backend can’t be reached |
Show "Can’t reach the server" |