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:
const passkeyApi =tenant({ tenantId:"<your tenant id>", apiKey:"<your secret api key>",});
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:
const creationOptions =await tenant.registration.initialize({ userId:"<id of the user in your database>", username:"<username of the user>",});
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.