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.
Output:
3 Replies
Are you sure you get the
displayName
field from the db?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.
"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