0.2.1 • Published 1 year ago
@teamhanko/passkeys-sdk v0.2.1
Hanko Passkeys JavaScript SDK
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.
npm i @teamhanko/passkeys-sdkyarn add @teamhanko/passkeys-sdkbun add @teamhanko/passkeys-sdkpnpm add @teamhanko/passkeys-sdkUsage
A tenant is an API client instance for one tenant of the Hanko Passkey API.
Create a new tenant instance:
const passkeyApi = tenant({
tenantId: "<your tenant id>",
apiKey: "<your secret api key>",
});Make sure the API key stays secret. It should never be exposed to the client/frontend. If you're using a framework that handles both frontend and backend (like Next.js, for example), create two separate tenant instances, each in their own file (e.g. tenant-server.ts and tenant-client.ts).
- 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
baseUrlas well.
Now you're ready to call the API. For example, to start the process of registering a new passkey:
const creationOptions = await tenant.registration.initialize({
userId: "<id of the user in your database>",
username: "<username of the user>",
});