From be6b51582dfe00399e504477818a4544d9d4dcd0 Mon Sep 17 00:00:00 2001 From: Maxime Brochard Date: Wed, 9 Oct 2024 10:06:02 +0200 Subject: [PATCH] Fixes csv export with getServerSession --- src/utils/api.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils/api.ts b/src/utils/api.ts index bb4825b..76f87a3 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -1,5 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next'; -import { getSession } from 'next-auth/react'; +import { getServerSession } from 'next-auth/next'; + +import { authOptions } from '@/lib/auth'; type HttpVerbs = 'GET' | 'POST' | 'DELETE' | 'PATCH' | 'PUT'; type Methods = { @@ -46,7 +48,10 @@ export const apiMethods = } if (!method.isPublic) { - const session = await getSession({ req }); + // getSession is now deprecated and is way slower than getServerSession because + // it does an extra fetch out over the internet to confirm data from itself + const session = await getServerSession(req, res, authOptions); + if (!session) { return notSignedIn(res); }