Currently, I am utilizing the next-auth/discord
and facing an issue with the session
callback not setting the user id to the session property as expected.
[...nextauth].js
import NextAuth from "next-auth/next";
import DiscordProvider from "next-auth/providers/discord";
export default NextAuth({
providers: [
DiscordProvider({
...
session: {
strategy: "jwt",
...
},
callbacks: {
async session({ session, user }) {
session.user.id = user.id;
return session;
}
}
})
]
});
/api/page.js
import { getSession } from 'next-auth/react';
export default async function handler(req, res) {
const session = await getSession({ req });
console.log(session);
}
Upon logging the session object, it outputs:
{
user: {
name: ...,
email: ...,
image: ...
},
expires: ...
}
However, the user.id
property is missing in the output.