Output debug mode?

Is there any way to output more debugging stuff? I'm getting an error which is quite difficult to debug;
error PostgresError: column "undefined" does not exist
error PostgresError: column "undefined" does not exist
23 Replies
bekacru
bekacru2w ago
can you share here your auth config?
rhys
rhysOP2w ago
Of course!
export const auth = betterAuth({
appName: PUBLIC_APP_NAME,
baseURL: PUBLIC_URL,
emailAndPassword: {
enabled: true,
},
user: {
modelName: 'directus_users',
fields: {
name: 'first_name',
email: 'email',
image: 'avatar',
createdAt: 'date_created',
updatedAt: 'date_updated',
emailVerified: 'email_verified',
}
},
session: {
modelName: 'directus_sessions',
fields: {

userId: 'user',
expiresAt: 'expires',
ipAddress: 'ip',
userAgent: 'user_agent',
token: 'token',
createdAt: 'date_created',
updatedAt: 'date_updated',
}
},
verification: {
modelName: 'verification',
fields: {
createdAt: 'date_created',
updatedAt: 'date_updated',
expiresAt: 'expires_at' ,
value: 'value',
identifier: 'identifier',
},
},
database: drizzleAdapter(db, {
schema: {
verification,
directus_users,
directus_sessions,
account
},
provider: "pg", // or "pg" or "mysql"
}),
}
export const auth = betterAuth({
appName: PUBLIC_APP_NAME,
baseURL: PUBLIC_URL,
emailAndPassword: {
enabled: true,
},
user: {
modelName: 'directus_users',
fields: {
name: 'first_name',
email: 'email',
image: 'avatar',
createdAt: 'date_created',
updatedAt: 'date_updated',
emailVerified: 'email_verified',
}
},
session: {
modelName: 'directus_sessions',
fields: {

userId: 'user',
expiresAt: 'expires',
ipAddress: 'ip',
userAgent: 'user_agent',
token: 'token',
createdAt: 'date_created',
updatedAt: 'date_updated',
}
},
verification: {
modelName: 'verification',
fields: {
createdAt: 'date_created',
updatedAt: 'date_updated',
expiresAt: 'expires_at' ,
value: 'value',
identifier: 'identifier',
},
},
database: drizzleAdapter(db, {
schema: {
verification,
directus_users,
directus_sessions,
account
},
provider: "pg", // or "pg" or "mysql"
}),
}
I'm trying to get Better Auth using the existing auth tables for Directus, a headless CMS. Unfortunately, their auth isn't quite as well thought out, and they colocate their account stuff with their user table, which (amongst other things) means that they can't have multiple OAuth providers attached to the same account. So I have manually created the missing account and verification tables, and am remapping the users and sessions tables that already exist. I'm just trying to get the sign up w/ email working as a proof of concept, but I'm running into the error when I try the auth.api.signUpEmail() method.
rhys
rhysOP2w ago
Directus Docs
Authentication | Directus Docs
Explore our resources and powerful data engine to build your projects confidently.
bekacru
bekacru2w ago
If you're using drizzle, this error is thrown form drizzle rather than better auth the error message is basically saying there is a missing column that better auth is trying to insert. And that column name is "undefined" which is weird can you try to update to latest beta pnpm i better-auth@beta
rhys
rhysOP2w ago
Ahh yeah, you're one hundred percent right, looks like it is a drizzle thing. And updating to the beta has resulted in a fun new error-
bash ERROR [Better Auth]: Failed to create user TypeError [ERR_INVALID_ARG_TYPE]: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Date
bash ERROR [Better Auth]: Failed to create user TypeError [ERR_INVALID_ARG_TYPE]: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Date
Looks like the type is wrong for one of the columns on the users table, but the only two are date_created and date_updated, which are timestamp({ mode: 'string' }).
export const directus_users = pgTable("directus_users", {
id: uuid().primaryKey().notNull(),
first_name: varchar({ length: 50 }),
last_name: varchar({ length: 50 }),
email: varchar({ length: 128 }),
password: varchar({ length: 255 }),
location: varchar({ length: 255 }),
title: varchar({ length: 50 }),
description: text(),
tags: json(),
avatar: uuid(),
language: varchar({ length: 255 }).default(sql`NULL`),
tfa_secret: varchar({ length: 255 }),
status: varchar({ length: 16 }).default('active').notNull(),
role: uuid(),
token: varchar({ length: 255 }),
last_access: timestamp({ withTimezone: true, mode: 'string' }),
last_page: varchar({ length: 255 }),
provider: varchar({ length: 128 }).default('default').notNull(),
external_identifier: varchar({ length: 255 }),
auth_data: json(),
email_notifications: boolean().default(true),
appearance: varchar({ length: 255 }),
theme_dark: varchar({ length: 255 }),
theme_light: varchar({ length: 255 }),
theme_light_overrides: json(),
theme_dark_overrides: json(),
short_bio: text(),
biography: text(),
hero_image: uuid(),
is_group: boolean().default(false),
social_media: json(),
date_created: timestamp({ mode: 'string' }),
date_updated: timestamp({ mode: 'string' }),
email_verified: boolean().default(false).notNull(),
}, (table) => [
foreignKey({
columns: [table.hero_image],
foreignColumns: [directus_files.id],
name: "directus_users_hero_image_foreign"
}).onDelete("set null"),
foreignKey({
columns: [table.role],
foreignColumns: [directus_roles.id],
name: "directus_users_role_foreign"
}).onDelete("set null"),
unique("directus_users_email_unique").on(table.email),
unique("directus_users_token_unique").on(table.token),
unique("directus_users_external_identifier_unique").on(table.external_identifier),
]);
export const directus_users = pgTable("directus_users", {
id: uuid().primaryKey().notNull(),
first_name: varchar({ length: 50 }),
last_name: varchar({ length: 50 }),
email: varchar({ length: 128 }),
password: varchar({ length: 255 }),
location: varchar({ length: 255 }),
title: varchar({ length: 50 }),
description: text(),
tags: json(),
avatar: uuid(),
language: varchar({ length: 255 }).default(sql`NULL`),
tfa_secret: varchar({ length: 255 }),
status: varchar({ length: 16 }).default('active').notNull(),
role: uuid(),
token: varchar({ length: 255 }),
last_access: timestamp({ withTimezone: true, mode: 'string' }),
last_page: varchar({ length: 255 }),
provider: varchar({ length: 128 }).default('default').notNull(),
external_identifier: varchar({ length: 255 }),
auth_data: json(),
email_notifications: boolean().default(true),
appearance: varchar({ length: 255 }),
theme_dark: varchar({ length: 255 }),
theme_light: varchar({ length: 255 }),
theme_light_overrides: json(),
theme_dark_overrides: json(),
short_bio: text(),
biography: text(),
hero_image: uuid(),
is_group: boolean().default(false),
social_media: json(),
date_created: timestamp({ mode: 'string' }),
date_updated: timestamp({ mode: 'string' }),
email_verified: boolean().default(false).notNull(),
}, (table) => [
foreignKey({
columns: [table.hero_image],
foreignColumns: [directus_files.id],
name: "directus_users_hero_image_foreign"
}).onDelete("set null"),
foreignKey({
columns: [table.role],
foreignColumns: [directus_roles.id],
name: "directus_users_role_foreign"
}).onDelete("set null"),
unique("directus_users_email_unique").on(table.email),
unique("directus_users_token_unique").on(table.token),
unique("directus_users_external_identifier_unique").on(table.external_identifier),
]);
bekacru
bekacru2w ago
mode should be date better auth tries to insert Date object
rhys
rhysOP2w ago
Nuts. Is there any way to coerce it? I don't think directus supports it being a Date.
bekacru
bekacru2w ago
if it's a pg database, use the builtin postgres adapter instead of drizzle from better auth side.
rhys
rhysOP2w ago
Thanks so much! I'll give that a shot. Ok! That worked too. Now, it's returning 2025-04-13T00:04:21.563Z ERROR [Better Auth]: Failed to create user error: invalid input syntax for type uuid: "b7g00pstBsS5FGSuTitnYGpkIxe2RBzK". The id generated by BetterAuth likely doesn't jive with the uuid PK. I can see the generateId function that's being called as part of the create user flow is a pretty straightforward wrapper, is there any possibility that this could be extended to allow for uuid use?
Enzo 文字Yakisobi何でも
maybe https://www.better-auth.com/docs/concepts/database#id-generation ? no idea, but I was doing that just fine in 1.2.4, but now with 1.2.6 i'm facing that error too
Database | Better Auth
Learn how to use a database with Better Auth.
bekacru
bekacru2w ago
have you set generateId to false?
Enzo 文字Yakisobi何でも
yes! i downgraded to 1.2.4 and it's working again
bekacru
bekacru2w ago
could you try setting advanced.database.generateId to false? the location is changed for the api but for the time being the old option should still work. will take a look
Enzo 文字Yakisobi何でも
ohhh ok! I had
advanced: {
generateId: false
}
advanced: {
generateId: false
}
rhys
rhysOP2w ago
I think the docs are just a touch out of date, generateId has shifted to database according to the intellisense
Enzo 文字Yakisobi何でも
indeed! now it's working on 1.2.6 thanks guys!
rhys
rhysOP2w ago
If database is an object, how do I pass the postgres pool? i.e.
database: {
generateId: false,
db: new Pool({
connectionString: DATABASE_URL
})
},
database: {
generateId: false,
db: new Pool({
connectionString: DATABASE_URL
})
},
adrrian17
adrrian172w ago
I have it like this in my code and the error is the same: invalid input syntax for type uuid: "u6XxTs8GfIKTfKwi9RnA1ucC9fOsIJII"
advanced: {
database: {
generateId: false,
},
},
advanced: {
database: {
generateId: false,
},
},
bekacru
bekacru2w ago
on 1.2.6? It should more look like this
const auth = betterAuth({
dataabase: new Pool(),
advanced: {
database: {
geenrateId: false
}
}
})
const auth = betterAuth({
dataabase: new Pool(),
advanced: {
database: {
geenrateId: false
}
}
})
adrrian17
adrrian172w ago
Sorry, I was using 1.2.5 but when I changed to 1.2.6 now I get this error: null value in column "id" of relation "user" violates not-null constraint. BTW, the problem started when I added the "admin" plugin
bekacru
bekacru2w ago
if you're using drizzle make sure each id field has auto generate id from the database
adrrian17
adrrian172w ago
thanks, that actually worked. This is how the IDs are generated in the Drizzle schema > id: uuid('id').primaryKey().$default(() => randomUUID()) 😄
rhys
rhysOP6d ago
Hot damn! It's at the very least inserted the dummy data in the user table in the db- I get
error {"length":130,"name":"error","severity":"ERROR","code":"42703","position":"38","file":"parse_target.c","line":"1065","routine":"checkInsertTargets"}
error {"length":130,"name":"error","severity":"ERROR","code":"42703","position":"38","file":"parse_target.c","line":"1065","routine":"checkInsertTargets"}
. The account table is empty, but this is well and truly progress.

Did you find this page helpful?