Integrating Passkey Authentication with Contribyard in Next.js (Example)
Prerequisites
Before starting, ensure you have:- A Next.js application.
- Installed the
@github/webauthn-json
package. - Access to the Contribyard API.
Step 1: Install Required Dependencies
In your Next.js project, install the necessary npm package:Step 2: Configure Contribyard API
Set up your environment variables for Contribyard API access by adding the following to your.env.local
file:
your_contribyard_api_key
with your actual API key from Contribyard.
Step 3: Implement Registration Flow
Create aregister.js
page in your Next.js pages
directory for the user registration flow.
Step 4: Create API Endpoints for the Registration Flow
Create two API routes in thepages/api/
directory to interact with Contribyard’s /v1/passkey_attestations
and /v1/passkey_attestations/{id}/verify
endpoints.
register-challenge.js
This endpoint retrieves the attestation options from Contribyard:
register.js
This endpoint verifies the attestation:
Step 5: Implement Authentication Flow
Now, let’s implement the authentication flow. Create alogin.js
page for user authentication.
Step 6: Create API Endpoints for the Authentication Flow
Create two API routes to handle authentication using the/v1/passkey_assertions
and /v1/passkey_assertions/{id}/verify
endpoints.