From f1ff6b0a413a6107e9a4dfbfdf8d7e818944559c Mon Sep 17 00:00:00 2001 From: Thomas Ruoff Date: Wed, 8 Dec 2021 23:42:53 +0100 Subject: [PATCH] cache mongo client - not sure if it makes a diff :shrug: --- pages/api/auth/[...nextauth].ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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; }