Auth.js (next-auth) with Drizzle Provider Typescript

Hello so in the guide for the drizzle provider for Auth.js (next-auth) it says we can override the tables for example if i want to give me my users table a password and role field but then i run into a typescript error since the tables are typed in a specific way inside the adapter itself
adapter: {
/**
* Argument of type '{ usersTable: SQLiteTableWithColumns<{ name: "user"; schema: undefined; columns: { id: SQLiteColumn<{ name: "id"; tableName: "user"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: [...]; baseColumn: never; }, object>; ... 5 more ...; role...' is not assignable to parameter of type 'DefaultSQLiteSchema'.
Type '{ usersTable: SQLiteTableWithColumns<{ name: "user"; schema: undefined; columns: { id: SQLiteColumn<{ name: "id"; tableName: "user"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: [...]; baseColumn: never; }, object>; ... 5 more ...; role...' is missing the following properties from type 'DefaultSQLiteSchema': accountsTable, sessionsTable, verificationTokensTablets(2345)
*/
...DrizzleAdapter(db, { usersTable: users }),
adapter: {
/**
* Argument of type '{ usersTable: SQLiteTableWithColumns<{ name: "user"; schema: undefined; columns: { id: SQLiteColumn<{ name: "id"; tableName: "user"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: [...]; baseColumn: never; }, object>; ... 5 more ...; role...' is not assignable to parameter of type 'DefaultSQLiteSchema'.
Type '{ usersTable: SQLiteTableWithColumns<{ name: "user"; schema: undefined; columns: { id: SQLiteColumn<{ name: "id"; tableName: "user"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: [...]; baseColumn: never; }, object>; ... 5 more ...; role...' is missing the following properties from type 'DefaultSQLiteSchema': accountsTable, sessionsTable, verificationTokensTablets(2345)
*/
...DrizzleAdapter(db, { usersTable: users }),
3 Replies
KHRM
KHRMOP7mo ago
currently I am overriding the specific functions of the adapter as needed (although i should probably override all of them to keep it consistent)
adapter: {
...DrizzleAdapter(db, ),
/** here users points to my users table not the one from inside the adapter **/
async createUser(data: AdapterUser) {
const hasDefaultId = getTableColumns(users)["id"]["hasDefault"];

return db
.insert(users)
.values(hasDefaultId ? data : { ...data, id: crypto.randomUUID() })
.returning()
.get();
},
async getUserByAccount(
account: Pick<AdapterAccount, "provider" | "providerAccountId">,
) {
const result = await db
.select({
account: accounts,
user: users,
})
.from(accounts)
.innerJoin(users, eq(accounts.userId, users.id))
.where(
and(
eq(accounts.provider, account.provider),
eq(accounts.providerAccountId, account.providerAccountId),
),
)
.get();

return result?.user ?? null;
},
},
adapter: {
...DrizzleAdapter(db, ),
/** here users points to my users table not the one from inside the adapter **/
async createUser(data: AdapterUser) {
const hasDefaultId = getTableColumns(users)["id"]["hasDefault"];

return db
.insert(users)
.values(hasDefaultId ? data : { ...data, id: crypto.randomUUID() })
.returning()
.get();
},
async getUserByAccount(
account: Pick<AdapterAccount, "provider" | "providerAccountId">,
) {
const result = await db
.select({
account: accounts,
user: users,
})
.from(accounts)
.innerJoin(users, eq(accounts.userId, users.id))
.where(
and(
eq(accounts.provider, account.provider),
eq(accounts.providerAccountId, account.providerAccountId),
),
)
.get();

return result?.user ?? null;
},
},
Sillvva
Sillvva7mo ago
Currently you have to define all 4 tables. There is a PR so that you only need to define the user and account tables, but it hasn't been merged/released yet. There is a discussion about it on the Auth.js server. https://discord.gg/7vQCDXdd9h Here is the thread: https://discord.com/channels/1200116961590399008/1231534836859146241
KHRM
KHRMOP7mo ago
Ahh that's not too bad at least for my case I'm just setting it to themselves basically, at least it's more consistent then me overriding the functions
Want results from more Discord servers?
Add your server