lucia
lucia copied to clipboard
[Bug]: incompatible types with generatedAlwaysAsIdentity
Package
@lucia-auth/session-drizzle
Describe the bug
When I try to use the generatedAlwaysAsIdentity()
function on the id
column from users, TypeScript presents the following type compatibility error
The types of '_.inferInsert' are incompatible between these types.
Type '{ name: string; }' has no properties in common with type '{ id?: number | undefined;
Example code:
const userTable = pgTable("users", {
id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
name: text("name").notNull(),
});
const adapter = new DrizzlePostgreSQLAdapter(db, sessionTable, userTable);
Apparently, the type PgTableWithColumns
from Drizzle enforces that the id
property should exist on $inferInsert
type as well, even though it's not necessary since we don't insert users via Lucia.
Workaround:
const adapter = new DrizzlePostgreSQLAdapter(
db,
sessionTable,
userTable as PostgreSQLUserTable,
);