Skip to content

Commit

Permalink
Fixes csv export with getServerSession
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeBro committed Oct 9, 2024
1 parent 6fae34c commit be6b515
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit be6b515

Please sign in to comment.