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.
- 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.
- 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.
- 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.
- 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.