I encountered a typescript error while trying to implement a MongoDB adapter in my Next Auth config. My goal is to utilize Next Auth for user authentication using MongoDB as the database.
Currently, I am working with Next Auth V5.
Below is a snippet from my Next Auth configuration file:
import type { NextAuthConfig } from 'next-auth'
import Credentials from 'next-auth/providers/credentials'
import { MongoDBAdapter } from "@auth/mongodb-adapter"
import mongoClientPromise from './app/lib/mongodb'
export default {
providers: [
Credentials({
async authorize(credentials) {
const user = { name: 'admin', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2f4e4b4246416f555a5d464c47014c4042">[email protected]</a>', password: '123456' }
if (credentials.user === user.name && credentials.password === user.password) return user
console.log('Invalid credentials')
return null
},
}),
],
adapter: MongoDBAdapter(mongoClientPromise)
} satisfies NextAuthConfig
The issue arises within the 'adapter' key and the specific error message is: ** Type 'AdapterAccount' is not assignable to type 'Promise | Awaitable<AdapterAccount | null | undefined>'. Type 'AdapterAccount' is missing the following properties from type 'Promise': then, catch, finally, [Symbol.toStringTag]**
Any suggestions on how to resolve this problem?
I have followed various tutorials meticulously, such as the one on Medium linked here: and also consulted the official documentation: but unfortunately, the error persists
UPDATE:
To resolve the issue, I made the following adjustment:
import type { Adapter } from "@auth/core/adapters"
Then updated the 'adapter' key as shown below:
adapter : <Adapter>MongoDBAdapter(mongoClientPromise)