next-auth drizzle adapter customization

Hi folks, I'm using t3 app dir stack with next-auth and drizzle. I wanna customize the drizzle adapter while creating a user. I inspected the source code and customized the createUser callback function of the adapter as the following:
// node_modules/@auth/drizzle-adapter/src/lib/pg.ts
async createUser(data){
console.log("createUser", data)
return await client
.insert(users)
.values({
...data,
id: crypto.randomUUID(),
username: data.email.split("@")[0] // added this by myself
}).returning().then((res) => res[0] ?? null)
},
// node_modules/@auth/drizzle-adapter/src/lib/pg.ts
async createUser(data){
console.log("createUser", data)
return await client
.insert(users)
.values({
...data,
id: crypto.randomUUID(),
username: data.email.split("@")[0] // added this by myself
}).returning().then((res) => res[0] ?? null)
},
I have extended my users table by adding password and email columns and need to set the username column with notNull restriction using the email without domain like you see above. the problem is that the username value still gets null somehow even though the email is not null so I can't add users since the notNull restriction error. It seems that my changes doesn't work at all, how do I customize this adapter as I need ?
5 Replies
Furki4_4
Furki4_4OP13mo ago
I solved it creating my own adapter instead of changing the source code. The username gets what I expected above.
skuse
skuse13mo ago
hey man, im having trouble with this too, mind sharing your solution?
Furki4_4
Furki4_4OP13mo ago
GitHub
Turkish-Dictionary/db/CustomDrizzleAdapter.ts at 4Furki4/issue55 · ...
Turkish Dictionary is an open-source website where people can search and save words, and contribute to Turkish! - 4Furki4/Turkish-Dictionary
Furki4_4
Furki4_4OP13mo ago
GitHub
Turkish-Dictionary/src/server/auth.ts at 0354e677d4fd57c3b927777ee3...
Turkish Dictionary is an open-source website where people can search and save words, and contribute to Turkish! - 4Furki4/Turkish-Dictionary
Furki4_4
Furki4_4OP13mo ago
hey dude@skuse did my code do the trick for you ?
Want results from more Discord servers?
Add your server