Skip to content

Passkey names

A passkey shows a name in the browser and in the password manager that stores it, so a user with several passkeys can tell which one is which. You pass that name when you create the passkey, and Keyhaw never receives it. The name stays in the browser, so Keyhaw stores none of it and no request carries it.

Pick the name you show. With no name, or with one that is blank, the passkey shows your instance’s name, the same as a passkey made from <Account /> or <RecoverAccount />. A name you set is the first thing a user sees in their password manager, so write the name they will recognize, such as their own name or the email address they sign up with.

A name proves nothing. If you pass an email address, the passkey shows that address, but Keyhaw does not check it, and nothing ties the passkey to the person who owns the address. Verify an address in your own system before you rely on it.

The sign-up button reads the name from the form it sits in. Mark the input with autocomplete="email webauthn", and the client takes its value as the passkey’s name, so the button needs no other setup.

<form>
<input name="name" type="email" autocomplete="email webauthn" />
<button id="sign-up" type="submit">Create account</button>
</form>

Pass the button to signUp, and the client finds the input. To set the name yourself, pass name instead.

import { createKeyhaw } from "keyhaw/client"
const keyhaw = createKeyhaw()
// The client reads the input marked `webauthn` in the button's form.
const button = document.querySelector<HTMLButtonElement>("#sign-up")
if (button) await keyhaw.signUp({ button })
// Or pass the name yourself.
await keyhaw.signUp({ name: "Ada Lovelace" })

A user.creating handler runs before the passkey is made, and the name is read after every handler has run, so a handler can change the form before the passkey takes its name.

A signed-in user adds a passkey with passkeys.add, and the same rule applies. Pass a name, or leave it out to show the instance’s name.

await keyhaw.passkeys.add({ name: "Work laptop" })

Recovery works the same way. When a user recovers their account with a backup code on a new device, pass the name the new passkey should show.

await keyhaw.recover({ code, name: "Phone" })

To change the name of the passkey the user is signed in with, call passkeys.updateName. It resolves signaled, which tells you whether the browser took the new name.

const { data } = await keyhaw.passkeys.updateName({ name: "Work laptop" })
// data.signaled is false in a browser without the Signal API.

Some browsers and password managers take a new name through the Signal API, and then the password manager shows the new name. A browser without the Signal API cannot tell the password manager a new name, so signaled is false, and the password manager keeps the old name until the user renames the passkey there. Show the user that, rather than promising that the name has changed.