Extending next-auth user

I'm trying to extend the next-auth user but somehow It's not returning new fields, and I only have this with drizzle with prisma It's working fine.
declare module "next-auth" {
interface Session extends DefaultSession {
user: {
id: string;
// ...other properties
displayName: string;
} & DefaultSession["user"];
}

interface User {
// ...other properties
displayName: string;
}
}

callbacks: {
session: ({ session, user }) => {
console.log(user);
console.log(user.displayName);

return {
...session,
user: {
...session.user,
displayName: user.displayName,
id: user.id,
},
};
},
},
declare module "next-auth" {
interface Session extends DefaultSession {
user: {
id: string;
// ...other properties
displayName: string;
} & DefaultSession["user"];
}

interface User {
// ...other properties
displayName: string;
}
}

callbacks: {
session: ({ session, user }) => {
console.log(user);
console.log(user.displayName);

return {
...session,
user: {
...session.user,
displayName: user.displayName,
id: user.id,
},
};
},
},
Output:
{
id: '965a6ae9-375f-40df-a527-af2e5a31db83',
name: 'thoo0224',
email: 'xxx@gmail.com',
emailVerified: 2024-04-02T14:34:00.000Z,
image: 'https://cdn.discordapp.com/xxx'
}
undefined
{
id: '965a6ae9-375f-40df-a527-af2e5a31db83',
name: 'thoo0224',
email: 'xxx@gmail.com',
emailVerified: 2024-04-02T14:34:00.000Z,
image: 'https://cdn.discordapp.com/xxx'
}
undefined
S
stoyko16d ago
Are you sure you get the displayName field from the db?
RE
Rasmus Eklund16d ago
I had this exact question on the drizzle discord. This is the answer i got: "I believe, by default, Drizzle only returns columns included in the table declaration that you pass to a select query. It doesn't do SELECT * FROM table, because it needs to get back the columns in a specific order. Internally, Auth.js (also known as Next Auth) Drizzle adapter passes its own table declarations to the queries. So even if your table declaration has more columns, the Drizzle adapter doesn't know about them. If you want additional columns, you'd need to make an additional query to get them in the session callback and return the session with the updated user." I made an additional db call in the callback to add the data i needed.
S
stoyko16d ago
"I believe, by default, Drizzle only returns columns included in the table declaration that you pass to a select query. It doesn't do SELECT * FROM table, because it needs to get back the columns in a specific order. This is also a good way to avoid calling unnecessary data, which is good. What I don't understand is Internally, Auth.js (also known as Next Auth) Drizzle adapter passes its own table declarations to the queries. So even if your table declaration has more columns, the Drizzle adapter doesn't know about them. It's strange, but hey, as long as it works! You should mark your reply as the solution to your question, so that people in the future know it's solved and can reference it
Want results from more Discord servers?
Add your server
More Posts
Are cold starts an issue?I haven't used Next API routes as a primary API before, and from what I understand they are mostly sI have a doubt .I have a doubt . suppose i am using a hosting platform which offers some free but limited resources Expo Router headerSearchBarOptionsHi folks, struggling quite a bit to try and implement the native iOS search bar in the header of a tIm a newbie creating a document editor and idk how to setup an architecture to save the dataI'm using tip tap for the editor on the front end while using Postgresql with bun on the back end. IDifferences Between ProvidersI'm in a small team and we are looking for some cloud providers to have the following things: - Servhow to use yarnrc.ymlI found this ``` nodeLinker: node-modules plugins: - path: .yarn/plugins/@yarnpkg/plugin-workspacA guide for tRPC MySQL drizzle testing setupHey folks I have built a product using t3 stack with MySQL db and drizzle as the ORM. I would like tshadcn/ui: Why do I get the incorrect error message?If I don't type anything in I only get the "required" message despite defining a message in the zod TRPCClientError: Unable to transform response from serverI just migrated from Next Auth to Clerk. Clerk is working fine. tRPC works fine too, but I keep gettBasic system design questions for a big projectHey, I am making a fairly ambitious app and wanted some advice on how to proceed with my system desiValidation error in JSON schema provided by user against the JSON Schema draft 2020-12?I have integrated monaco editor on my website and I want users to input JSON data and validate it agHow to change refType in forwardRef based on prop?imagine you want a React component to have a certain ref type if some prop is present, and another r