export default NextAuth({
...
callbacks: {
session: async ({ session, token }) => {
if (session?.user) {
session.user.id = token.uid;
}
return session;
},
jwt: async ({ user, token }) => {
if (user) {
token.uid = user.id;
}
return token;
},
},
session: {
strategy: 'jwt',
},
...
});
I'm curious about the statement "if (session?.user)
". Can someone explain its meaning to me?
- Why is it written as "
if (session.user?)
" instead of "if (session?.user)
"? - I thought the question mark operator should be followed by a colon to express true and false situations. Why is there just a question mark in this case?