Skip to main content
1

Install passkey provider

Once you’ve initialized your Next app with NextAuth, install passkey provider and the webauthn-json package.
2

Get your tenant ID and API key

Get your tenant ID and API key from Hanko Cloud and add them to your .env.local file.
.env.local
If you’re self-hosting:
  1. make sure to pass the baseUrl to both tenant (in [...nextauth].ts) and signInWithPasskey() (in your component).
  2. get your tenant ID via the admin API
3

Add `PasskeyProvider`

app/api/auth/[...nextauth]/route.ts
4

Allow your users to register passkeys as a login method for their account

Your users will have to add passkeys to their account somehow. It’s up to you how and where you let them do this, but typically this would be a button on an “Account Settings” page.On your backend, you’ll have to call tenant({ ... }).registration.initialize() and .registration.finalize() to create and store a passkey for your user.On your frontend, you’ll have to call create() from @github/webauthn-json with the object .registration.initialize() returned.create() will return a PublicKeyCredential object, which you’ll have to pass to .registration.finalize().Backend:
lib/passkey-registration.ts
Frontend:
components/PasskeyRegistrationButton.tsx
5

Allow your users to log in with passkeys

Let’s add a button that triggers the “Sign in with passkey” dialog:
components/PasskeyLoginButton.tsx
6

Optional: Autofill support

If you don’t want to add a button just for passkeys, you can add autofill support to your username (or email) fields:
Clicking on any passkey in the autofill popup will immediately log the user in, going through the same flow as if they had clicked the “Sign in with passkey” button earlier in this guide.To add autofill support:
  • add autoComplete="username webauthn" to your username field
  • call signInWithPasskey.conditional() when the login form loads
Example:
7

Try it yourself

Next.js with Auth.js example

Full source code available on our GitHub