PasskeyServer

The one object you construct, and every method it exposes.

The one object you construct. Everything on the server side hangs off it.

import { PasskeyServer, MemoryStore } from 'passkify';
 
const passkeys = new PasskeyServer({
  rpName: 'Acme',
  origin: 'https://acme.com',
  store: new MemoryStore(),
});

Create it once, at module scope, and share it across requests. It holds no per-request state.

Constructor

new PasskeyServer(config)constructor

new PasskeyServer(config: PasskeyServerConfig)

Validates the configuration eagerly and throws PasskeyError('configuration_error') if anything is wrong. Every option is documented on configuration.

Why configuration is validated at construction, not at first use

Throws

configuration_error

Properties

rpIDproperty

readonly rpID: string

The Relying Party ID in force, after defaulting from origin.

Why it works this way

storeproperty

readonly store: PasskeyStore

The store the server was constructed with. Handy in tests and for admin tooling that needs to reach credentials directly.

The four ceremony methods

These are the whole API. Two to start a ceremony, two to finish one.

startRegistrationmethod

startRegistration(input: StartRegistrationInput): Promise<StartRegistrationResult>

Begins registering a passkey. Send the returned options to the browser verbatim. Covered in full on registration.

// New account
const { options } = await passkeys.startRegistration({ username: 'ada' });
 
// Signed-in user adding another device
const { options } = await passkeys.startRegistration({ userId: session.userId });

finishRegistrationmethod

finishRegistration(response: RegistrationResponseJSON): Promise<VerifyRegistrationResult>

Verifies the browser's response and stores the credential. Throws on any failure. Full check list on registration.

startAuthenticationmethod

startAuthentication(input?: StartAuthenticationInput): Promise<StartAuthenticationResult>

Begins a login. Call it with no arguments for the usernameless flow, which is what you want. See authentication.

const { options } = await passkeys.startAuthentication();

finishAuthenticationmethod

finishAuthentication(response: AuthenticationResponseJSON): Promise<VerifyAuthenticationResult>

Verifies an assertion. On success the returned user is authenticated and you should establish your session. See authentication.

Credential management

Covered on credential management.

listCredentialsmethod

listCredentials(userId: string): Promise<PublicCredentialInfo[]>

renameCredentialmethod

renameCredential(userId: string, credentialId: string, nickname: string): Promise<void>

deleteCredentialmethod

deleteCredential(userId: string, credentialId: string): Promise<void>

HTTP adapters

Rather than writing the four routes yourself. Covered on HTTP adapters.

expressmethod

express(options?: ExpressAdapterOptions): (req, res, next) => Promise<void>

Express and Connect middleware. Also works on a bare node:http server, because it parses its own JSON body when none has been parsed already.

handlermethod

handler(options?: FetchAdapterOptions): (request: Request) => Promise<Response>

A standards Request to Response handler for Next.js App Router, Hono, Bun, Deno, Remix and Cloudflare Workers.

Why two adapters and not a plugin system

Next