Username plugin with drizzle adapter gives Types errors

I was setting up a very simple better auth example with express (i know i know, but I'm doing an experiment ๐Ÿ˜„ ) but even before setting up anything I have this very weird type error when using the username plugin with the drizzle adapter.
import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { db } from '../db/index.ts'; // your drizzle instance
import { username } from 'better-auth/plugins';

export const auth = betterAuth({
plugins: [username()],
database: drizzleAdapter(db, {
provider: 'sqlite',
}),
});
import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { db } from '../db/index.ts'; // your drizzle instance
import { username } from 'better-auth/plugins';

export const auth = betterAuth({
plugins: [username()],
database: drizzleAdapter(db, {
provider: 'sqlite',
}),
});
here's my better auth instance...i did run generate and this is my drizzle instance
import { createClient } from '@libsql/client';
import { drizzle } from 'drizzle-orm/libsql';
import * as schema from './schema.ts';

const client = createClient({
url: 'file:notes.db',
});

export const db = drizzle(client, {
schema,
});
import { createClient } from '@libsql/client';
import { drizzle } from 'drizzle-orm/libsql';
import * as schema from './schema.ts';

const client = createClient({
url: 'file:notes.db',
});

export const db = drizzle(client, {
schema,
});
i get this error:
Type '{ id: "username"; init(ctx: AuthContext): { options: { databaseHooks: { user: { create: { before(user: { id: string; email: string; emailVerified: boolean; name: string; createdAt: Date; updatedAt: Date; image?: string | ... 1 more ... | undefined; } & Record<...>, context: GenericEndpointContext | undefined): Promi...' is not assignable to type 'BetterAuthPlugin'.
// other stuff
The types of 'data.id' are incompatible between these types.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.

7 plugins: [username()],
Type '{ id: "username"; init(ctx: AuthContext): { options: { databaseHooks: { user: { create: { before(user: { id: string; email: string; emailVerified: boolean; name: string; createdAt: Date; updatedAt: Date; image?: string | ... 1 more ... | undefined; } & Record<...>, context: GenericEndpointContext | undefined): Promi...' is not assignable to type 'BetterAuthPlugin'.
// other stuff
The types of 'data.id' are incompatible between these types.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.

7 plugins: [username()],
any ideas?
4 Replies
Ping
Pingโ€ข2mo ago
Can you show me your tsconfig?
{๐Ÿงช} paoloricciuti
{
// Visit https://aka.ms/tsconfig to read more about this file
"compilerOptions": {
// File Layout
// "rootDir": "./src",
// "outDir": "./dist",

// Environment Settings
// See also https://aka.ms/tsconfig/module
"allowImportingTsExtensions": true,
"noEmit": true,
"module": "nodenext",
"target": "esnext",
"types": [],
// For nodejs:
// "lib": ["esnext"],
// "types": ["node"],
// and npm install -D @types/node

// Other Outputs
"sourceMap": true,
"declaration": true,
"declarationMap": true,

// Stricter Typechecking Options
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,

// Style Options
// "noImplicitReturns": true,
// "noImplicitOverride": true,
// "noUnusedLocals": true,
// "noUnusedParameters": true,
// "noFallthroughCasesInSwitch": true,
// "noPropertyAccessFromIndexSignature": true,

// Recommended Options
"strict": true,
"jsx": "react-jsx",
"verbatimModuleSyntax": true,
"isolatedModules": true,
"noUncheckedSideEffectImports": true,
"moduleDetection": "force",
"skipLibCheck": true
}
}
{
// Visit https://aka.ms/tsconfig to read more about this file
"compilerOptions": {
// File Layout
// "rootDir": "./src",
// "outDir": "./dist",

// Environment Settings
// See also https://aka.ms/tsconfig/module
"allowImportingTsExtensions": true,
"noEmit": true,
"module": "nodenext",
"target": "esnext",
"types": [],
// For nodejs:
// "lib": ["esnext"],
// "types": ["node"],
// and npm install -D @types/node

// Other Outputs
"sourceMap": true,
"declaration": true,
"declarationMap": true,

// Stricter Typechecking Options
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,

// Style Options
// "noImplicitReturns": true,
// "noImplicitOverride": true,
// "noUnusedLocals": true,
// "noUnusedParameters": true,
// "noFallthroughCasesInSwitch": true,
// "noPropertyAccessFromIndexSignature": true,

// Recommended Options
"strict": true,
"jsx": "react-jsx",
"verbatimModuleSyntax": true,
"isolatedModules": true,
"noUncheckedSideEffectImports": true,
"moduleDetection": "force",
"skipLibCheck": true
}
}
Ping
Pingโ€ข2mo ago
Turn off declaration & declarationMap (and maybe sourceMap, though not too sure about that one)
{๐Ÿงช} paoloricciuti
nope that's not it but is exactOptionalPropertyTypes ๐Ÿ˜„ thanks ๐Ÿ˜„

Did you find this page helpful?