

# 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
<a name="backend-auth-passkeys-turn-on"></a>

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](backend-auth-config.md).

```jsonc
// 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](backend-auth-managed-sign-in.md) 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
<a name="backend-auth-passkeys-add"></a>

To let a signed-in user create a passkey, call `passkey.addPasskey`.

```typescript
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.

**Note**  
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](backend-auth-passwordless.md).

## Sign users in with a passkey
<a name="backend-auth-passkeys-sign-in"></a>

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](https://github.com/aws-amplifygen3/amplifygen3/blob/main/packages/client-sdk/js/README.md) on GitHub.

```typescript
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 name="backend-auth-passkeys-domain"></a>

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`.

```jsonc
// 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
<a name="backend-auth-passkeys-settings"></a>

Set these in `plugins.passkey` in the `auth` block.


| Setting | Values | Default | 
| --- | --- | --- | 
|  `enabled`  |  `true`, `false`  |  `false`  | 
|  `rpId`  | A host with no scheme or port, 1 to 253 characters of letters, digits, `.` and `-`. Required when the origins span more than one host | The host of the one origin | 
|  `origins`  | Up to 5 exact origins, each a scheme, host and port | Your `trustedOrigins` entries without a `*`, or the origin that the browser calls the backend on. Locally, also the dev servers that `aws amplifygen3 local run` trusts on the `rpId` host | 

## Errors
<a name="backend-auth-passkeys-errors"></a>

The client SDK returns each error’s code in `error.code`.


| Code | When | What to do | 
| --- | --- | --- | 
|  `PASSKEY_USER_VERIFICATION_REQUIRED`  | 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 | 
|  `403 PASSKEY_ORIGIN_MISMATCH`  | With no `rpId`, `origins` or exact `trustedOrigins` entry, the passkey was created or used on another host than the one the browser calls the backend on | Set `rpId` and `origins`  | 
|  `CONFIG_RETRIEVAL_FAILED`  | A deployment where `origins` has a wildcard over hosts that others own | List each origin exactly | 
|  `error.status` is `0`  | The backend can’t be reached | Show "Can’t reach the server" | 