Skip to main content
The @teamhanko/passkeys-sdk package lets you call the Hanko Passkey API from JavaScript/TypeScript that supports fetch. This includes Node.js, Browsers, Deno, Bun, and frameworks like Next.js, Astro, and SvelteKit.

Usage

A tenant is an API client instance for one tenant of the Hanko Passkey API.
If the app you’re building supports organizations, teams, or anything similar, you will likely have heard of multitenancy.The Passkey API supports multitenancy as well — you can create tenants (a.k.a. organizations, teams, …) and add the passkeys of users exclusively to those tenants. Then your users will only be able to log in with passkeys specifically for that tenant.For example: In your app, a user is part of two teams: the “ACME Corp.” and the “A-Team.”They create a passkey to log into “ACME Corp.”That passkey will only work for the “ACME Corp.”, not the “A-Team”.
If you use Hanko Cloud, get your tenant ID and API key from the dashboard. Create a new tenant instance:
  • If you only use public API methods, like /login/initialize, you can omit the apiKey.
  • If you’re self-hosting the Passkey API, make sure to pass the baseUrl as well.
Now you’re ready to call the API. For example, to start the process of registering a new passkey:

Example Implementation

1

Install the SDK

2

Get your tenant ID and API key

Get your tenant ID and API key from Hanko Cloud and add them to your .env file.
.env
3

Allow users to register passkeys as a login method

On your backend, you’ll have to call tenant({ ... }).registration.initialize() and registration.finalize() to create and store a passkey.
services.js
controllers.js
FrontendOn your frontend, the registerPasskey() function handles the passkey registration process. It first sends a request to the server to initiate the registration process and receives the response for creating a new passkey.It then uses the @github/webauthn-json library to create a new passkey credential based on the received options from the response. Finally, it sends another request to the server with the newly created credential to complete the registration process.
4

Allow users to log in with passkeys

services.js
controllers.js
Frontend

Try it yourself

Check out sample apps made using the SDK:

React-Express Example

Full source code available on our GitHub.

Remix example

Full source code available on our GitHub.