I am trying to retrive the data of a user from mongodb atlas using prisma client and I write this code for the fetching of the data and It shows error, Here the prisma client code are written in the prismadb file which is imported as prisma
import { NextApiRequest, NextApiResponse } from "next";
import prisma from "./prismadb";
import { getServerSession } from "next-auth";
const serverAuth = async (req: NextApiRequest, res: NextApiResponse) => {
try {
const session = await getServerSession(req);
if (!session?.user?.email) {
throw new Error('Not signed in');
}
const currentUser = await prisma.user.findUnique({
where: {
email: session.user.email,
}
});
if (!currentUser) {
throw new Error('Not signed in');
}
return { currentUser };
} catch (error:any) {
// res.status(500).json({ error: `&{err.message}` });
res.status(500).json({ error: error.message });
return;
}
};
export default serverAuth;
I have given the try and catch and this error shows up. I have asked in the chat GPT and it suggests that this may be due to some error between next.js and next-auth and in teh official GitHub account of the Issue is closed but I don't understand any thing
Here are the reference links:
and in next-auth https://github.com/nextauthjs/next-auth/issues/6989