October 5, 2022

How to Create a NextAuth.js Custom Adapter with HarperDB & Next.js

Welcome to Community Posts
Click below to read the full article.
Summary of What to Expect
Table of Contents

We’re going to learn how to create a Custom Adapter for NextAuth.js that will allow us to persist our sessions in a database.

  1. Configuring a new NextAuth.js Custom Adapter: Create a new directory called "adapters" and a file "harperdb.js" with template configuration for 10 methods required by NextAuth.js.
  2. Creating a new HarperDB instance and Tables for managing data: Create a new HarperDB Cloud Instance, select AWS or Verizon as the Cloud Provider, and set up Schema and Tables for Users, Accounts, and Sessions.
  3. Creating a HarperDB client to make secure queries to a database: Create a function "harperClient" to handle fetch requests with the API key and database URL.
  4. Setting up NextAuth.js Adapter methods to get and update data from HarperDB: Update the 10 methods in "harperdb.js" with appropriate queries and operations to interact with HarperDB.

Check out the video tutorial as well.