diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index b0b2e51..0f16ca4 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -6,11 +6,14 @@ import { MongoDBAdapter } from "@next-auth/mongodb-adapter" import { MONGO_URI, MONGODB_OPTIONS } from "../../../db" import { MongoClient } from "mongodb"; -let mongooseConnection: Mongoose; +let client: MongoClient; async function getMongoClient() { - const client = new MongoClient(MONGO_URI, MONGODB_OPTIONS); - await client.connect(); + if (!client) { + client = new MongoClient(MONGO_URI, MONGODB_OPTIONS); + await client.connect(); + } + return client; }