JavaScript/TypeScript SDK
A lean, type-safe, fetch
-based API client for the Hanko Passkey API
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 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 theapiKey
. - 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
Install the SDK
Get your tenant ID and API key
Get your tenant ID and API key from Hanko Cloud and add them to your .env
file.
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.
Frontend
On 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.
Allow users to log in with passkeys
Frontend
Try it yourself
Check out sample apps made using the SDK:
Was this page helpful?