Open Source. Full Stack. Own Your Data.
We introduced the new built-in Webauthn support for Auth.js - head over to https://authjs.dev/reference/core/providers/webauthn to learn more.
This example shows how to use NextAuth.js to add 2FA with WebAuthn. It uses SimpleWebAuthn, Vercel KV, and RedisUpstashAdapter. The steps are:
- Sign in with GitHub
- Register a WebAuthn credential
- Sign out & Sign in with GitHub again
- Verify the WebAuthn credential
- We need a DB to store the user's registered webauthn credential.
- When the user successfully registers a credential, set the flag
is2FAEnabled: true
- The next time he/she logs in, check for
is2FAEnabled
- if true, then prompt them with the Webauthn flow.
- When the user successfully registers a credential, set the flag
- Implement 2FA with Webauthn in the Credential Provider. Note: We need to use the
strategy: 'jwt'
here. You could find more details about the reasoning in the Credential Provider doc.