Extending session call back to include other information
Unanswered
TK2 posted this in #help-forum
TK2OP
I have a
What's the best way to return/read this within the application?
Extend the session callback?
Or is running the query inside the specific form component where the values are used the better approach?
Maybe something like this?
Notifications model in my schema model Notifications {
id String @id @default(cuid())
userId String
type NotificationType @default(none)
mobile Boolean
communication Boolean
social Boolean
marketing Boolean
security Boolean
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}What's the best way to return/read this within the application?
Extend the session callback?
Or is running the query inside the specific form component where the values are used the better approach?
Maybe something like this?
async session({ session, token, user } :any) {
session.user = token.data
const userNotifications = await prisma.notifications.findUnique({
where: {
id: token.data.id
},
select: {
type: true,
mobile: true,
communication: true,
social: true,
marketing: true,
security: true,
},
});
session.notifications = userNotifications;
return session;
},