How to return additional fields from user in session callback next-auth?

Hi all! I have the following schema:
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
role String?
seller Seller?
buyer Buyer?
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
role String?
seller Seller?
buyer Buyer?
}
Everything is working as it should in that aspect. In the callback:
session: async ({ session, user }) => {
if (session.user) {
session.user.id = user.id;
session.user.role = user.role;

console.log(user);

if (user.buyer) {
session.user.tutor = user.buyer;
}

if (user.seller) {
session.user.student = user.seller;
}
}

return session;
},
session: async ({ session, user }) => {
if (session.user) {
session.user.id = user.id;
session.user.role = user.role;

console.log(user);

if (user.buyer) {
session.user.tutor = user.buyer;
}

if (user.seller) {
session.user.student = user.seller;
}
}

return session;
},
That console log only includes fields such as name, email, image, id and role. I want it to be able to include user.buyer or user.seller for example, or any field for that matter. How can I do this? Please post your thoughts/ideas!
5 Replies
HonestCode
HonestCode2y ago
on same issue aswell
barry
barry2y ago
and console logging the session doesnt include the seller and buyer? oh im blind what is Seller and Buyer, enums? oh is not im confused wtf is a Seller type why was this even recommended its from a long ass time ago
HonestCode
HonestCode2y ago
RIiiiiight... so basically i fixed it my issue was that google auth when making a custom adapter wouldnt return all of the stuff i wanted next auth as i noticed, is kinda opinionated on the data it returns once authed i wish there was an option to choose what data comes through when authed, because right now by default you only get name but if you want to separate name and surname, youre shit out of luck
HonestCode
HonestCode2y ago
HonestCode
HonestCode2y ago
in next auth, i added an additional thing to make it return family name aswell. fixed my issue as i wanted to have both names separated
Want results from more Discord servers?
Add your server