Passkey authentication for Astro, Sveltekit and other frameworks
Passkey authentication for Astro, Sveltekit and other frameworks
Frictionless passkey authentication in under 30 minutes
[!TIP] Use our LLM Agent Skill to supercharge Codex, Claude, Copilot or your coding agent of choice :robot:
No SDK lock-in. No backend coupling.
This monorepo contains the public browser SDK, server SDK, CLI, and a reference SvelteKit example.
:unlock: No lock-in
Framework agnostic. Standards compliant.
:rocket: Zero config passkeys
Works out of the box with sensible defaults.
:arrow_right: Related origins
Migrate passkeys with backend-selected RP IDs and WebAuthn related-origin files.
:iphone: Credential management
Manage passkeys on end-user devices.
:muscle: Powerful
User verification, autofill, roaming authenticators and more.
You can be up and running with a working passkey flow in minutes :rocket:
Create a new Passlock tenancy:
npx @passlock/cli initTake a note of your Tenancy ID and API Key.
Passkey registration is a three-step process:
[!TIP] You only need to pass tokens (strings) between your backend and the browser, avoiding the need to handle JSON and binary data.
…Choose rpId in your backend for each prepared passkey ceremony. Passlock no
longer uses a separate tenancy-level passkey settings RP ID.
// frontend/register.ts
import { Passlock } from "@passlock/browser";
const tenancyId = "myTenancyId";
const passlock = new Passlock({ tenancyId });
// call this in a click handler or similar action
// ask your backend for a registration token
const registrationToken = await fetchRegistrationToken();
const result = await passlock.registerPasskey({ registrationToken });
if (result.failure) {
// handle the error
throw new Error(result.error.message);
}
// send result.code or result.id_token to your backend for verification
console.log("code: %s", result.value.code);In your backend, exchange the code to obtain details about the completed registration. We'll use the @passlock/server library for this, but you can also make vanilla REST calls or verify the id_token instead.
// backend/register.ts
import { Passlock } from "@passlock/server";
const tenancyId = "myTenancyId";
const apiKey = "myApiKey";
const passlock = new Passlock({ tenancyId, apiKey });
const result = await passlock.exchangeCode({ code });
if (result.failure) {
// handle the error
throw new Error(result.error.message);
}
// includes details about the completed registration
// link the authenticatorId to a local user account
console.log("user id: %s", result.value.userId);
console.log("passkey id: %s", result.value.authenticatorId);Passkey authentication follows the same backend-authorized pattern as registration:
// backend/authorize-authentication.ts
import { Passlock } from "@passlock/server";
const tenancyId = "myTenancyId";
const apiKey = "myApiKey";
const passlock = new Passlock({ tenancyId, apiKey });
const result = await passlock.authorizePasskeyAuthentication({
rpId: "example.com",
discoverable: true,
});
if (result.failure) {
// handle the error
throw new Error(result.error.message);
}
// send only this token to your frontend
console.log("authentication token: %s", result.value.authenticationToken);…[!TIP] To authenticate against a known account, authorize with
userId,allowCredentials, or both. For discoverable login, setdiscoverable: true; for autofill, also setmediation: "conditional".
In your backend, exchange the code and look up the user by userId or authenticatorId ...
// backend/authenticate.ts
import { Passlock } from "@passlock/server";
const tenancyId = "myTenancyId";
const apiKey = "myApiKey";
const passlock = new Passlock({ tenancyId, apiKey });
const result = await passlock.exchangeCode({ code });
if (result.failure) {
// handle the error
throw new Error(result.error.message);
}
// lookup the user based on their userId or authenticatorId
console.log("user id: %s", result.value.userId);
console.log("passkey id: %s", result.value.authenticatorId);[!TIP]
Not using a JS backend? The examples in this README use our @passlock/server server library, but this is not required. Passlock works similarly to OAuth2/OpenID Connect, so you can make vanilla HTTP calls or use any suitable JWT library to verify anid_token(JWT).
Please see the tutorial and documentation
If Passlock saved you time or helped you ship passkeys faster, a ⭐ on GitHub helps more than you think.
No open issues yet, or sync has not completed.