thal9201
thal9201
TTCTheo's Typesafe Cult
Created by thal9201 on 7/13/2023 in #questions
Next-Auth Access to custom data in sessions database
Hi All, I implemented a new column into the "sessions" table called "selectedClientID". Users will have access to multiple clients and I want the session to keep track of what client they have selected. In my current implementation, I can't seem to retrieve the "selectedClientID" in the sessions table. This is the current code:
callbacks: {
async session({ session, trigger, newSession, user, token }) {

session.user = {
...session.user,
role: user.role,
};
console.log("auth.ts: ", session);

if (trigger === "update" && newSession?.selectedClientID) {
session.selectedClientID = newSession.selectedClientID
}

return session;
},
},
callbacks: {
async session({ session, trigger, newSession, user, token }) {

session.user = {
...session.user,
role: user.role,
};
console.log("auth.ts: ", session);

if (trigger === "update" && newSession?.selectedClientID) {
session.selectedClientID = newSession.selectedClientID
}

return session;
},
},
In the above, ideally, the variable session would return the selected client and so if the trigger=== "update" and there is a new selectedClientID in "newSession", it would trigger an update and persist it to the database. I am unsure if I am looking at the problem the right way, so any help would be greatly appreciated. Many thanks!
21 replies