# FaunaDB adapter with NextAuth Test ## Issues encountered Console Log ``` error - ./pages/api/auth/[...nextauth].js:3:0 Module not found: Can't resolve '@next-auth/faunadb-adapter' 1 | import NextAuth from "next-auth" 2 | import Providers from "next-auth/providers" > 3 | import Adapter from "@next-auth/faunadb-adapter" 4 | import faunadb from "faunadb" ``` Nextjs runtime error ``` 1 of 1 unhandled error Unhandled Runtime Error TypeError: Cannot use 'in' operator to search for 'undefined' in null Call Stack eval node_modules/next-auth/dist/client/index.js (290:0) Generator.next <anonymous> asyncGeneratorStep node_modules/next-auth/dist/client/index.js (29:82) _next node_modules/next-auth/dist/client/index.js (31:192) ``` ## Steps to reproduce the errors ### Clone the repo and install dependencies ``` git clone https://github.com/nextauthjs/next-auth-example.git cd next-auth-example npm i ``` Copy the .env.local.example file in this directory to .env.local (which will be ignored by Git): ``` cp .env.local.example .env.local ``` Add details for one or more providers (e.g. Google, Twitter, GitHub, Email, etc). When configuring your database you should also install an appropriate node_module. We would be installing faunadb ``` npm uninstall sqlite3 npm i faunadb ``` #### FaunaDB Add Ennironment variable **FAUNADB_SECRET_KEY** and assign your server key Create the following Collections and Indexes in FaunaDB **Collections:** 1. users 1. accounts 1. sessions 1. verificationRequests **Indexes:** 1. index_users_id 1. index_users_email 1. index_accounts_providerId_providerAccountId 1. index_verificationRequests_token 1. index_sessions_id 1. index_sessions_sessionToken ### Install faunadb adapter and configure [..nextauth].js file as below ``` npm install --save-prod next-auth @next-auth/faunadb-adapter ``` **[...nextauth].js** ``` import NextAuth from "next-auth" import Providers from "next-auth/providers" import Adapter from "@next-auth/faunadb-adapter" import faunadb from "faunadb" const faunaClient = new faunadb.Client({ secret: process.env.FAUNADB_SECRET_KEY, }); // For more information on each option (and a full list of options) go to // https://next-auth.js.org/configuration/options export default NextAuth({ // https://next-auth.js.org/configuration/providers providers: [ Providers.Google({ clientId: process.env.GOOGLE_ID, clientSecret: process.env.GOOGLE_SECRET, }), ], adapter: Adapter({faunaClient}), ... }) ```