Next.js Discord

Discord Forum

how can I get modified session?

Unanswered
Rafeiro do Alentejo posted this in #help-forum
Open in Discord
Rafeiro do AlentejoOP
I set session callback function in nextauth option to return modified session which includes user id from database, and I used getServerSession() but I got original session information, which consists of session : {user : {name, email, image}}. I want to change it to include id.
How can I do that?
this is code from '/api/auth/[...nextauth]/route.js' file.

async session({ session }) {
const sessionUser = await User.findOne({
email: session.user.email
})
session.user.id = sessionUser._id.toString();

return session;
}

0 Replies