getServerSession in next-auth not working
Unanswered
Siberian posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
SiberianOP
Someone please help me !
![Image](https://cdn.discordapp.com/attachments/1222498340579577856/1222498340827299990/image.png?ex=66166f4d&is=6603fa4d&hm=2912d7514a60b05bb84f7dc154dbae4288261ce3fecb632062c3b4f4c5ba725f&)
2 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
SiberianOP
import db from '../../../utils/mongo';
import { getServerSession } from 'next-auth/react';
import { authOptions } from './auth/[...nextauth]';
export default async function handler(req, res) {
const session = await getServerSession(req, res, authOptions);
console.log(session)
if(session){
let foundEmail=await db.collection("users").findOne({email:session?.user?.email});
if(foundEmail){
res.json({msg:'email already exists'})
}
else{
await db.collection("users").insertOne({email:session.user.email,posts:[]});
res.json({msg:'Email added'})
}
}
res.json({msg:'hello'})
}
here is the full code![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Giant panda
correct this line
const session = await getServerSession(req, res, authOptions);
to
const session = await getServerSession(authOptions);
const session = await getServerSession(req, res, authOptions);
to
const session = await getServerSession(authOptions);