Next Auth Drizzle Adapter does not include extra columns (fields)

auth.ts
providers: [
GoogleProvider({
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
profile(profile: GoogleProfile) {
return {
id: profile.sub,
name: profile.name,
email: profile.email,
image: profile.picture,
username: removeEmailDomain(profile.email) ?? profile.email,
};
},
}),
providers: [
GoogleProvider({
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
profile(profile: GoogleProfile) {
return {
id: profile.sub,
name: profile.name,
email: profile.email,
image: profile.picture,
username: removeEmailDomain(profile.email) ?? profile.email,
};
},
}),
I have a schema for the user table with username field. When I try to add the username field in the profile callback as initial data for user creation, the Drizzle adapter doesn't include the username field, and instead returns default fields only. Is there a way to fix this?
Solution:
GitHub
feat(adapter-drizzle): add option to pass in schema by juliusmarmin...
☕️ Reasoning In other adapters, the adapter returns the entire table so if you have additional fields they will also be returned when the adapter queries the table. A good example here is if your ...
Jump to solution
1 Reply
Solution
iboughtbed
iboughtbed8mo ago
Found a workaround: https://github.com/nextauthjs/next-auth/pull/8561 auth.ts
export const authOptions {
...
adapter: {
...(DrizzleAdapter(db, createTable) as Adapter),
// @ts-expect-error drizzle adapter does not include extra columns
async createUser(data) {
return await db
.insert(users)
.values({ ...data, id: crypto.randomUUID() })
.returning()
.then((res) => res[0] ?? null);
},
},
export const authOptions {
...
adapter: {
...(DrizzleAdapter(db, createTable) as Adapter),
// @ts-expect-error drizzle adapter does not include extra columns
async createUser(data) {
return await db
.insert(users)
.values({ ...data, id: crypto.randomUUID() })
.returning()
.then((res) => res[0] ?? null);
},
},
GitHub
feat(adapter-drizzle): add option to pass in schema by juliusmarmin...
☕️ Reasoning In other adapters, the adapter returns the entire table so if you have additional fields they will also be returned when the adapter queries the table. A good example here is if your ...
Want results from more Discord servers?
Add your server