Skip to Content

Passkey

Passkey

Passkeys are a secure, passwordless authentication method using cryptographic key pairs, supported by WebAuthn and FIDO2 standards in web browsers. They replace passwords with unique key pairs: a private key stored on the user's device and a public key shared with the website. Users can log in using biometrics, PINs, or security keys, providing strong, phishing-resistant authentication without traditional passwords.

The passkey plugin implementation is powered by SimpleWebAuthn behind the scenes.

Installation

Install the plugin

npm install @entro314labs/entro-auth-passkey

Add the plugin to your auth config

To add the passkey plugin to your auth config, you need to import the plugin and pass it to the plugins option of the auth instance.

auth.ts
import { entroAuth } from "@entro314labs/entro-auth"
import { passkey } from "@entro314labs/entro-auth-passkey"

export const auth = entroAuth({
    plugins: [ 
        passkey(), 
    ],
})

Migrate the database

Run the migration or generate the schema to add the necessary fields and tables to the database.

npx @entro314labs/entro-auth-cli migrate

See the Schema section to add the fields manually.

Add the client plugin

auth-client.ts
import { createAuthClient } from "@entro314labs/entro-auth/client"
import { passkeyClient } from "@entro314labs/entro-auth-passkey/client"

export const authClient = createAuthClient({
    plugins: [
        passkeyClient() 
    ]
})

Configuration (Optional)

You can customize the passkey plugin to support passkey-first onboarding or WebAuthn extensions.

auth.ts
import { entroAuth } from "@entro314labs/entro-auth"
import { passkey } from "@entro314labs/entro-auth-passkey"

export const auth = entroAuth({
  plugins: [
    passkey({
      registration: {
        // Default: true. Set false for passkey-first onboarding.
        requireSession: false,
        // Required if requireSession is false and no session exists.
        resolveUser: async ({ ctx, context }) => {
          // Validate context (e.g., a signed token), then create or load a user.
          return { id: "user-id", name: "user@example.com" }
        },
        // Optional server-defined extensions
        extensions: { credProps: true },
      },
      authentication: {
        // Optional server-defined extensions
        extensions: { credProps: true },
      },
    }),
  ],
})

Passkey-first registration (pre-auth)

When registration.requireSession is false, passkey registration can be initiated without a session. You can pass an opaque context to the registration options endpoint; it will be forwarded to resolveUser.

await auth.api.generatePasskeyRegistrationOptions({
  context: "signed-registration-token",
})

When using passkey-first flows (registration.requireSession: false), pass the same context from the client when registering the passkey so the server can resolve the user during verification:

await authClient.passkey.addPasskey({
  name: "Primary passkey",
  context: "signed-registration-token",
  createSession: true,
})

When createSession is true, successful verification sets the session cookie and returns the session and user with the registered passkey. If you want to avoid creating a user before the WebAuthn ceremony succeeds, create or load the user in registration.afterVerification and return its userId.

With registration.requireSession: false, a registration started with a session must be verified with that same live session. One started without a session uses resolveUser.

Usage

Add/Register a passkey

To add or register a passkey make sure a user is authenticated and then call the passkey.addPasskey function provided by the client.

POST/passkey/add-passkey
const { data, error } = await authClient.passkey.addPasskey({    name: "example-passkey-name", // An optional name to label the authenticator account being registered. If not provided, it will default to the user's email address or user ID    authenticatorAttachment: "cross-platform", // You can also specify the type of authenticator you want to register. Default behavior allows both platform and cross-platform passkeys    extensions, // Optional WebAuthn extensions (e.g., PRF, credProps, largeBlob)    hints, // Where the browser should offer to keep the passkey first, for this call. Overrides the server's `registration.hints`    returnWebAuthnResponse, // Return WebAuthn response and extension results    context, // Optional context for passkey-first registration flows. Forwarded to `registration.resolveUser`.    createSession, // Create a session after successfully registering the passkey. The response includes the session and user when enabled.});
Parameters
namestring

An optional name to label the authenticator account being registered. If not provided, it will default to the user's email address or user ID

authenticatorAttachment"platform" | "cross-platform"

You can also specify the type of authenticator you want to register. Default behavior allows both platform and cross-platform passkeys

extensionsAuthenticationExtensionsClientInputs

Optional WebAuthn extensions (e.g., PRF, credProps, largeBlob)

hints("client-device" | "hybrid" | "security-key")[]

Where the browser should offer to keep the passkey first, for this call. Overrides the server's registration.hints

returnWebAuthnResponseboolean

Return WebAuthn response and extension results

contextstring

Optional context for passkey-first registration flows. Forwarded to registration.resolveUser.

createSessionboolean

Create a session after successfully registering the passkey. The response includes the session and user when enabled.

Setting throw: true in the fetch options has no effect for the register and sign-in passkey responses — they will always return a data object containing the error object.

Sign in with a passkey

To sign in with a passkey you can use the signIn.passkey method. This will prompt the user to sign in with their passkey.

POST/sign-in/passkey
const { data, error } = await authClient.signIn.passkey({    autoFill: true, // Browser autofill, a.k.a. Conditional UI. Read more: https://simplewebauthn.dev/docs/packages/browser#browser-autofill-aka-conditional-ui    extensions, // Optional WebAuthn extensions (e.g., PRF, credProps, largeBlob)    hints, // Where the browser should look for the passkey first, for this call. Overrides the server's `authentication.hints`    returnWebAuthnResponse, // Return WebAuthn response and extension results});
Parameters
autoFillboolean

Browser autofill, a.k.a. Conditional UI. Read more: https://simplewebauthn.dev/docs/packages/browser#browser-autofill-aka-conditional-ui

extensionsAuthenticationExtensionsClientInputs

Optional WebAuthn extensions (e.g., PRF, credProps, largeBlob)

hints("client-device" | "hybrid" | "security-key")[]

Where the browser should look for the passkey first, for this call. Overrides the server's authentication.hints

returnWebAuthnResponseboolean

Return WebAuthn response and extension results

Example Usage

import { authClient } from "@/lib/auth-client";

// With post authentication redirect
await authClient.signIn.passkey({
    autoFill: true,
    // Optional extensions
    extensions: { credProps: true },
    fetchOptions: {
        onSuccess(context) {
            // Redirect to dashboard after successful authentication
            window.location.href = "/dashboard";
        },
        onError(context) {
            // Handle authentication errors
            console.error("Authentication failed:", context.error.message);
        }
    }
});

Telling a closed prompt from a failure

addPasskey, signIn.passkey and verifySecondFactor return an error when the browser's prompt ends without an answer, also when nothing failed. getPasskeyCeremonyEnd reads which it was:

import { getPasskeyCeremonyEnd } from "@entro314labs/entro-auth-passkey/client";

const { error } = await authClient.passkey.addPasskey();
const ended = getPasskeyCeremonyEnd(error);
if (ended === "cancelled") return; // nothing to say
if (ended === "already-registered") {
  // this device already holds a passkey of the account
}
if (error) {
  // a failure worth showing
}
  • "cancelled": the person closed the prompt, let it time out, or the device had no passkey to offer. Browsers report the three alike, on purpose.
  • "already-registered": the device already holds a passkey of this account, so it made no second one.

It is undefined for a failure, such as a browser without WebAuthn or a request that did not reach the server, and for an error the server answered with. The code of these errors is unchanged, and signIn.passkey still codes a failure it cannot name as AUTH_CANCELLED; read the ending from getPasskeyCeremonyEnd, not from the code.

Extensions

You can use WebAuthn extensions through the client API by passing extensions. When returnWebAuthnResponse is true, the client returns webauthn.clientExtensionResults.

const result = await authClient.passkey.addPasskey({
  name: "My Passkey",
  extensions: {
    // Example extension input (generic)
    credProps: true,
  },
  returnWebAuthnResponse: true,
});

console.log(result.webauthn?.clientExtensionResults);

List passkeys

You can list all of the passkeys for the authenticated user by calling passkey.listUserPasskeys:

GET/passkey/list-user-passkeys
const { data: passkeys, error } = await authClient.passkey.listUserPasskeys();

Naming passkeys by authenticator

When a user registers a passkey without naming it, the stored name is left empty. You can show a friendly default in your UI instead, derived from the authenticator that created the credential.

Every passkey row carries an aaguid, the identifier of the authenticator model (for example Google Password Manager or 1Password). Entro Auth stores it at registration and returns it from listPasskeys, so you resolve a label at the point you render passkeys. Because resolution happens at read time, an updated provider list applies to passkeys that already exist.

The plugin ships a small, best-effort lookup for the most common authenticators:

passkey-list.tsx
import { getAuthenticatorName } from "@entro314labs/entro-auth-passkey";

const passkeys = await authClient.passkey.listUserPasskeys();

for (const passkey of passkeys.data ?? []) {
    const label = passkey.name || getAuthenticatorName(passkey.aaguid) || "Passkey";
}

The built-in list is intentionally small and not authoritative. Many authenticators are missing, and privacy-preserving platforms report an all-zero AAGUID that resolves to nothing (Apple devices do this under the default attestation: "none" flow). Extend it with the exported commonAuthenticatorNames map, or resolve against the community-maintained source for full coverage:

passkey-list.tsx
import { commonAuthenticatorNames } from "@entro314labs/entro-auth-passkey";

const names = { ...commonAuthenticatorNames, "your-aaguid": "Your Provider" };

To set a default label on the server at registration time, return a name from registration.afterVerification. The AAGUID is available on verification.registrationInfo.aaguid, and a client-supplied name always takes precedence:

auth.ts
import { entroAuth } from "@entro314labs/entro-auth";
import { passkey, getAuthenticatorName } from "@entro314labs/entro-auth-passkey";

export const auth = entroAuth({
    plugins: [
        passkey({
            registration: {
                afterVerification: async ({ verification }) => ({
                    name: getAuthenticatorName(verification.registrationInfo?.aaguid),
                }),
            },
        }),
    ],
});

Deleting passkeys

You can delete a passkey by calling passkey.delete and providing the passkey ID.

POST/passkey/delete-passkey
const { data, error } = await authClient.passkey.deletePasskey({    id: "some-passkey-id", // required, The ID of the passkey to delete.});
Parameters
idstringrequired

The ID of the passkey to delete.

Removing a passkey needs a fresh session, as adding one does: from a session that signed in longer ago than session.freshAge, the request is refused with 403 SESSION_NOT_FRESH. Have the person prove who they are again (their password, a code by email, or their second step), then repeat it.

Updating passkey names

POST/passkey/update-passkey
const { data, error } = await authClient.passkey.updatePasskey({    id: "id of passkey", // required, The ID of the passkey which you want to update.    name: "my-new-passkey-name", // required, The new name which the passkey will be updated to.});
Parameters
idstringrequired

The ID of the passkey which you want to update.

namestringrequired

The new name which the passkey will be updated to.

A passkey as the second factor

A passkey can be the second step after a password: a security key, or the platform authenticator of the device.

Turn it on beside the two-factor plugin:

auth.ts
import { entroAuth } from "@entro314labs/entro-auth";
import { twoFactor } from "@entro314labs/entro-auth/plugins";
import { passkey } from "@entro314labs/entro-auth-passkey";

export const auth = entroAuth({
    plugins: [
        twoFactor(),
        passkey({ secondFactor: true }), 
    ],
});

An account with two-factor on and a passkey registered is then offered "passkey" among its twoFactorMethods after a password sign in. Take the step with the client:

two-factor.ts
const { data, error } = await authClient.passkey.verifySecondFactor({
    trustDevice: true, // optional
});

An account whose only second step is a passkey turns two-factor on in two calls. It needs a passkey registered first:

// Starts the setup and answers the backup codes. Two-factor is not on yet.
const { data } = await authClient.twoFactor.enable({ password, method: "passkey" });
showBackupCodes(data.backupCodes);

// Using a passkey of the account, while signed in, is what turns it on.
await authClient.passkey.verifySecondFactor();

The second call proves the person still holds the key, so two-factor cannot be turned on with a passkey that was lost. Signed in, it has that one purpose: when there is no setup to finish, because none was started or because two-factor was turned on another way meanwhile and the setup was discarded, it answers SETUP_NOT_STARTED and not success. A setup is finished once: after a call that failed halfway, or after two-factor was turned off, the next one answers SETUP_NOT_STARTED, and enable, which asks for the password, starts again. When enable answers without backup codes, two-factor is already on and the account's codes stay as they are; the call that follows then answers success with nothing to finish, also for an account whose second step so far is a finished authenticator app. With nothing to finish, that success is proof the person is there now: the session is renewed, as a right code from an authenticator app renews it. It gets a new token, which the response carries, and is fresh again for a change that asks for a recent sign-in. The backup codes are the way in on the day the key is not at hand: a password sign in to such an account is answered with twoFactorBackupCodes: true, and authClient.twoFactor.verifyBackupCode takes the step. A setup that is never finished changes nothing, and starting again replaces its codes. Two setups started at the same moment do not both stand: the call whose setup is not the stored one answers SETUP_ALREADY_STARTED, so nobody keeps codes that were not stored. The account's last passkey cannot be removed while the setup is being finished, and a setup is not finished for an account that has no passkey left (PASSKEY_NOT_FOUND).

An authenticator app can be added later with twoFactor.enable({ password }). The backup codes the account already has stay as they are and are not answered again, so an app setup that is left unfinished takes nothing away.

The step is the two-factor plugin's own challenge, so it shares its rules:

  • It only answers a sign in a password left pending, and only with a passkey of that account. Another account's passkey is refused.
  • A pending sign in takes five wrong answers across all its methods, then has to start again.
  • Failures count toward the account lockout when the account also has an authenticator app.
  • Each WebAuthn challenge is answered once.

The last passkey of an account cannot be deleted while it is the account's only second step. Add another passkey, an authenticator app or a sent code, or turn two-factor off first. The account is read from the database for this check, not from a cached session.

Removing a passkey and finishing a passkey setup each claim the account for the moment they take, as every change to its two-factor does, so one happens at a time: of two requests that remove the last two passkeys at the same moment one is refused, and a passkey cannot go while a setup that counts on it is being finished. A call that finds the account claimed answers SECOND_FACTOR_CHANGE_IN_PROGRESS (409). It changed nothing and can be sent again. A claim whose request died expires after 30 seconds. The removal of a passkey is announced in the claim before the passkey is deleted, and from then on the passkey does not count as one of the account's: if the delete is still on its way when the claim has run out, the request that takes the account over decides without it, so a setup is never finished on a passkey that is about to go. A delete that fails is tried once more. Where the adapter runs transactions, the delete gets one of its own, and a statement the database refuses inside it is rolled back with it: the passkey is known to be where it was, the announcement is withdrawn, and the answer is PASSKEY_NOT_REMOVED (409). The passkey counts again and other passkeys can be removed. Without transactions, or when the transaction's commit is what failed, the answer is PASSKEY_REMOVAL_PENDING (503) and the announcement stays, because an error then does not tell a delete that was refused from one that is still on its way. The account's next change tries the delete again; until it goes through, that passkey counts for nothing in a setup, as the proof that finishes one or as the last passkey, no other passkey of the account can be removed, and every attempt is logged. It still signs in. The account's other changes are not held up. The claim is the two-factor plugin's: a member of the account's row, so it holds on every database and id strategy.

Deleting or renaming a passkey reads the session from the database, so a session that was revoked cannot change passkeys from a browser that still holds a cached cookie.

Signing in with a passkey alone

A passkey sign in is not asked for a second step. With secondFactor on, an account that has two-factor on can therefore sign in with a passkey alone only when the passkey checked who was holding it, with a PIN, a fingerprint or a face. That is the key and one thing more. A key that was only touched is one factor, and the sign in is refused with USER_VERIFICATION_REQUIRED: the person signs in with their password and takes the second step.

Authenticators check their user when they can under the default userVerification: "preferred". Two cases are not covered:

  • An account without a password is let through. The second step is only ever asked after a password, so it has no other way in.
  • Registering a passkey with createSession opens a session by that passkey alone, so the same check is made for the account the passkey ends up on, before anything is stored. A request that is already signed in is not asked, since it has taken its second step. This is the same rule, not a proof of who owns the account: a key registered a moment ago says nothing about that, and your resolveUser is what vouches for it.

A key for the second step only

Any registered passkey can also sign in on its own, which skips the password. To keep passkeys as a second step and nothing else, turn passkey sign in off:

auth.ts
passkey({ secondFactor: true, disableSignIn: true })

The sign-in routes then answer SIGN_IN_DISABLED, and so does registering a passkey with createSession, before its challenge is spent. Registering a passkey while signed in, and the second step, work as before. This is one setting for the whole server: a single account cannot hold one passkey that signs in and another that does not.

Conditional UI

The plugin supports conditional UI, which allows the browser to autofill the passkey if the user has already registered a passkey.

There are two requirements for conditional UI to work:

Update input fields

Add the autocomplete attribute with the value webauthn to your input fields. You can add this attribute to multiple input fields, but at least one is required for conditional UI to work.

The webauthn value should also be the last entry of the autocomplete attribute.

<label for="name">Username:</label>
<input type="text" name="name" autocomplete="username webauthn">
<label for="password">Password:</label>
<input type="password" name="password" autocomplete="current-password webauthn">

Preload the passkeys

When your component mounts, you can preload the user's passkeys by calling the authClient.signIn.passkey method with the autoFill option set to true.

To prevent unnecessary calls, we will also add a check to see if the browser supports conditional UI.

useEffect(() => {
   if (!PublicKeyCredential.isConditionalMediationAvailable ||
       !PublicKeyCredential.isConditionalMediationAvailable()) {
     return;
   }

  void authClient.signIn.passkey({ autoFill: true })
}, [])

Depending on the browser, a prompt will appear to autofill the passkey. If the user has multiple passkeys, they can select the one they want to use.

Some browsers also require the user to first interact with the input field before the autofill prompt appears.

Post-quantum passkeys

When the server runtime can verify ML-DSA (RFC 9964), a post-quantum signature, the plugin offers ML-DSA-44 (COSE -48) first for new passkeys, then EdDSA (-8), ES256 (-7) and RS256 (-257). That is Node.js 24.7.0 or later and Deno 2.8.2 or later. Elsewhere it offers the classical algorithms only. The authenticator picks the algorithm.

A runtime without ML-DSA cannot verify an ML-DSA passkey at sign-in. If sign-in may run on one, such as Cloudflare Workers without the webcrypto_modern_algorithms compatibility flag or an older Node.js, pin the classical algorithms with registration.algorithms. A passkey made with an algorithm outside the list is refused at registration.

auth.ts
passkey({
  registration: {
    // COSE algorithm identifiers, most preferred first.
    algorithms: [-8, -7, -257],
  },
})

The publicKey column holds the key in base64: about 1.8 KB for an ML-DSA-44 passkey, against about 100 bytes for ES256. The generated schemas store it as text (varchar(8000) on MSSQL), which fits.

Debugging

To test your passkey implementation you can use emulated authenticators. This way you can test the registration and sign-in process without even owning a physical device.

Schema

The plugin require a new table in the database to store passkey data.

Table Name: passkey

Table
Field
Type
Attributes
Description
id
string
PK
Unique identifier for each passkey
name ?
string
-
The name of the passkey
publicKey
string
-
The public key of the passkey
userId
string
FK
The ID of the user
credentialID
string
-
The unique identifier of the registered credential
counter
number
-
The counter of the passkey
deviceType
string
-
The type of device used to register the passkey
backedUp
boolean
-
Whether the passkey is backed up
transports ?
string
-
The transports used to register the passkey
createdAt ?
Date
-
The time when the passkey was created
aaguid ?
string
-
Authenticator's Attestation GUID indicating the type of the authenticator

Options

secondFactor: Let a passkey answer the two-factor plugin's second step, after a password. Default is false. See A passkey as the second factor.

disableSignIn: Refuse sign in by passkey alone, so that a passkey is only ever a second step. Default is false. See A key for the second step only.

rpID: A unique identifier for your website based on your auth server origin. 'localhost' is okay for local dev. RP ID can be formed by discarding zero or more labels from the left of its effective domain until it hits an effective TLD. So www.example.com can use the RP IDs www.example.com or example.com. But not com, because that's an eTLD.

rpName: Human-readable title for your website.

origin: The origin, or list of origins, where passkey registration and authentication run, without a trailing /. Defaults to the origin of baseURL, plus a frontend origin listed exactly in trustedOrigins.

auth.ts
passkey({
  origin: ["https://app.example.com", "https://admin.example.com"],
});

When rpID is set and a wildcard in baseURL.allowedHosts covers it, the default changes. Every host under that wildcard can create passkey responses for the shared rpID, and the client picks the host it sends. So the plugin ignores the request host. It accepts the origin the passkey reports only when that exact origin is trusted:

  • an exact entry in baseURL.allowedHosts, such as example.com
  • the baseURL.fallback origin
  • an origin listed exactly in trustedOrigins

A wildcard entry in either list does not count.

For tenants that you create at runtime, pass a function as trustedOrigins and return the origin only for tenants that your app knows:

auth.ts
entroAuth({
  baseURL: { allowedHosts: ["example.com", "*.example.com"] },
  trustedOrigins: async (request) => {
    const origin = request?.headers.get("origin");
    if (!origin) return [];
    // Look the origin up in your own tenant records.
    return (await isKnownTenantOrigin(origin)) ? [origin] : [];
  },
  plugins: [passkey({ rpID: "example.com" })],
});

An origin that trustedOrigins returns is trusted beyond passkeys, for example for CSRF checks and redirect URLs. Return only origins that your app serves, never an origin copied from the request without a lookup. Compare the full origin, including scheme and port, not only the hostname.

Entro Auth calls this function on every request, so cache the lookup. If you call the passkey verify endpoints through auth.api, pass the browser request's headers, including Host and Origin. Otherwise request is undefined, and the tenant origin is not trusted.

authenticatorSelection: Allows customization of WebAuthn authenticator selection criteria. Leave unspecified for default settings.

  • authenticatorAttachment: Specifies the type of authenticator
    • platform: Authenticator is attached to the platform (e.g., fingerprint reader)
    • cross-platform: Authenticator is not attached to the platform (e.g., security key)
    • Default: not set (both platform and cross-platform allowed, with platform preferred)
  • residentKey: Determines credential storage behavior.
    • required: User MUST store credentials on the authenticator (highest security)
    • preferred: Encourages credential storage but not mandatory
    • discouraged: No credential storage required (fastest experience)
    • Default: preferred
  • userVerification: Controls biometric/PIN verification during registration and authentication:
    • required: User MUST verify identity (highest security). Responses without user verification are rejected.
    • preferred: Verification encouraged but not mandatory
    • discouraged: No verification required (fastest experience)
    • Default: preferred

registration.hints, authentication.hints: Where the browser should offer a passkey first, in order of preference: "client-device" (the device in hand: Touch ID, Windows Hello), "hybrid" (a phone, by QR code) or "security-key". Without a hint, a desktop browser may open on a phone or a security key before the device's own fingerprint reader.

auth.ts
passkey({
  registration: { hints: ["client-device"] },
  authentication: { hints: ["client-device"] },
});

A hint orders the choices the browser shows and removes none, which is the difference from authenticatorSelection.authenticatorAttachment. A browser that does not know hints ignores them. The client's addPasskey({ hints }) and signIn.passkey({ hints }) override them for one call. The second step by passkey is not hinted: it names the account's own passkeys.

advanced: Advanced options

  • webAuthnChallengeCookie: Cookie name for storing WebAuthn challenge ID during authentication flow (Default: entro-auth-passkey)

Android apps

An Android app has no web origin. Android names it by the certificate the build is signed with, and ties it to your site through a file the site serves. Both come from the SHA-256 fingerprint of that certificate, which Play Console and keytool print as 32 pairs of hex digits.

Add the app's origin to the plugin's origin list, beside the site's own:

auth.ts
import { androidPasskeyOrigin, passkey } from "@entro314labs/entro-auth-passkey";

passkey({
  rpID: "example.com",
  origin: [
    "https://example.com",
    androidPasskeyOrigin(process.env.ANDROID_CERT_SHA256!),
  ],
});

And serve the Digital Asset Links statement at /.well-known/assetlinks.json on the host that rpID names:

app/.well-known/assetlinks.json/route.ts
import { androidAssetLinks } from "@entro314labs/entro-auth-passkey";

export function GET() {
  return Response.json(
    androidAssetLinks({
      packageName: "com.example.app",
      sha256Fingerprints: [process.env.ANDROID_CERT_SHA256!],
    }),
  );
}

Use the certificate your released builds are signed with. With Play App Signing that is the app signing key Play Console shows, not your upload key. Never name the debug keystore that project templates ship: its key is public, so any app signed with it and carrying your package name could use your site's passkeys.

Native apps

A native app has no navigator.credentials, so passkeyClient() as it comes cannot run a ceremony there. Hand it the platform's own passkey sheet as ceremony: two calls that take the options the server generated and answer what the server verifies. Everything else is the same client: addPasskey, signIn.passkey, verifySecondFactor, the list.

With Expo and react-native-passkeys:

auth-client.ts
import { createAuthClient } from "@entro314labs/entro-auth/react";
import { expoClient } from "@entro314labs/entro-auth-expo/client";
import {
  passkeyCeremonyEnded,
  passkeyClient,
} from "@entro314labs/entro-auth-passkey/client";
import * as SecureStore from "expo-secure-store";
import * as Passkeys from "react-native-passkeys";

export const authClient = createAuthClient({
  baseURL: "https://example.com",
  plugins: [
    expoClient({ scheme: "myapp", storage: SecureStore }),
    passkeyClient({
      ceremony: {
        async create(options) {
          const answer = await Passkeys.create(options);
          if (answer === null) throw passkeyCeremonyEnded("cancelled");
          return answer;
        },
        async get(options) {
          const answer = await Passkeys.get(options);
          if (answer === null) throw passkeyCeremonyEnded("cancelled");
          return answer;
        },
      },
    }),
  ],
});

Throw passkeyCeremonyEnded("cancelled") when the person closed the sheet, and passkeyCeremonyEnded("already-registered") when the device already holds a passkey of the account, so the app can tell them from a failure. How a native module reports a closed sheet is its own: read it from the module's errors. The browser-only switches (autoFill, useAutoRegister) do nothing with a ceremony of your own.

The passkeys belong to your site, so the app has to be tied to it:

  • iOS: add webcredentials:example.com to the app's associated domains, and serve { "webcredentials": { "apps": ["<team id>.<bundle id>"] } } as JSON at /.well-known/apple-app-site-association. The app answers from the site's own origin, so the plugin's origin needs nothing added.
  • Android: see Android apps.

The server keeps the challenge of a ceremony in a cookie, which the Expo client has to store and send back. It stores the cookies whose names start with its cookiePrefix. The default challenge cookie, entro-auth-passkey, starts with the default prefix, so nothing needs setting. If you rename it with advanced.webAuthnChallengeCookie, give the Expo client a matching cookiePrefix:

passkey({ advanced: { webAuthnChallengeCookie: "my-app-passkey" } }); // server
expoClient({ storage: SecureStore, cookiePrefix: "my-app" }); // client

On this page