BA
Better Auth•3w ago
Connor

Drizzle Postgres UUID

How can I force better-auth to use uuid's for id's and rely on the database to generate them with the drizzle adapter. The below doesn't seem to work.
advanced: {
database: {
generateId: false,
},
}
advanced: {
database: {
generateId: false,
},
}
This PR merged seems it got rid of the behavior? https://github.com/better-auth/better-auth/pull/2248
13 Replies
Ping
Ping•3w ago
Previously in an older PR, I changed schema generation to use uuid over text. However this was a major breaking change for all users who previously used our schema generation - a mistake on my end. If they had an existing schema which used ids as text (which has been what we've always been using until my breaking PR) then using schema generation after my breaking-pr would cause all id fields to convert to uuid. Because of this, their schema's can't be pushed since text can't convert to uuid. Right now, there isn't a way for you to tell the schema generation to use uuid for id fields. You will have to manually replace each id field to use uuid.
Connor
ConnorOP•2w ago
Thank you for the info! One more question, the better-auth schema is overwriting my drizzle schema everytime and reverting any changes I make too it. Is that expected or is it supposed to merge in changes?
Ping
Ping•2w ago
It prompts you if you want to overwrite. There isn't merging functionality as of now.
JROCBABY
JROCBABY•5d ago
@Ping I don't really understand, I changed the id's from text to uuid in my schema's manually, but I still get:
SERVER_ERROR: PostgresError: invalid input syntax for type uuid: "OjUrWCMOhxxxxxxxxxxxxxxxx"
at ErrorResponse (webpack-internal:///(rsc)/../../node_modules/postgres/src/connection.js:803:66)
at handle (webpack-internal:///(rsc)/../../node_modules/postgres/src/connection.js:489:6)
at Socket.data (webpack-internal:///(rsc)/../../node_modules/postgres/src/connection.js:330:9)
at Socket.emit (node:events:524:28)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at TCP.onStreamRead (node:internal/stream_base_commons:191:23)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '22P02',
where: "unnamed portal parameter $1 = '...'",
file: 'uuid.c',
line: '134',
routine: 'string_to_uuid'
}
POST /api/auth/sign-in/social 500 in 1318ms
SERVER_ERROR: PostgresError: invalid input syntax for type uuid: "OjUrWCMOhxxxxxxxxxxxxxxxx"
at ErrorResponse (webpack-internal:///(rsc)/../../node_modules/postgres/src/connection.js:803:66)
at handle (webpack-internal:///(rsc)/../../node_modules/postgres/src/connection.js:489:6)
at Socket.data (webpack-internal:///(rsc)/../../node_modules/postgres/src/connection.js:330:9)
at Socket.emit (node:events:524:28)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at TCP.onStreamRead (node:internal/stream_base_commons:191:23)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '22P02',
where: "unnamed portal parameter $1 = '...'",
file: 'uuid.c',
line: '134',
routine: 'string_to_uuid'
}
POST /api/auth/sign-in/social 500 in 1318ms
nomyom-db-1 | 2025-04-25 17:41:18.811 UTC [25855] ERROR: invalid input syntax for type uuid: "OjUrWCxxxxxxxxxxxxxxxxxx"
nomyom-db-1 | 2025-04-25 17:41:18.811 UTC [25855] CONTEXT: unnamed portal parameter $1 = '...'
nomyom-db-1 | 2025-04-25 17:41:18.811 UTC [25855] STATEMENT: insert into "verifications" ("id", "identifier", "value", "expires_at", "created_at", "updated_at") values ($1, $2, $3, $4, $5, $6) returning "id", "identifier", "value", "expires_at", "created_at", "updated_at"
nomyom-db-1 | 2025-04-25 17:41:18.811 UTC [25855] ERROR: invalid input syntax for type uuid: "OjUrWCxxxxxxxxxxxxxxxxxx"
nomyom-db-1 | 2025-04-25 17:41:18.811 UTC [25855] CONTEXT: unnamed portal parameter $1 = '...'
nomyom-db-1 | 2025-04-25 17:41:18.811 UTC [25855] STATEMENT: insert into "verifications" ("id", "identifier", "value", "expires_at", "created_at", "updated_at") values ($1, $2, $3, $4, $5, $6) returning "id", "identifier", "value", "expires_at", "created_at", "updated_at"
Ping
Ping•5d ago
Are you on the latest better-auth?
JROCBABY
JROCBABY•5d ago
Yeah I just installed it
Ping
Ping•5d ago
Can you enable debugLogs in your adapter options?
JROCBABY
JROCBABY•5d ago
Yeah I'll try it later, I just went out to buy some beer, sorry
export const verificationsTable = pgTable('verifications', {
id: uuid('id').primaryKey().defaultRandom(),
identifier: text('identifier').notNull(),
value: text('value').notNull(),
expiresAt: timestamp('expires_at').notNull(),
createdAt: createTimestampColumn('created_at'),
updatedAt: createTimestampColumn('updated_at', true),
});
export const verificationsTable = pgTable('verifications', {
id: uuid('id').primaryKey().defaultRandom(),
identifier: text('identifier').notNull(),
value: text('value').notNull(),
expiresAt: timestamp('expires_at').notNull(),
createdAt: createTimestampColumn('created_at'),
updatedAt: createTimestampColumn('updated_at', true),
});
So it complains about the id column, since the postgres error mentions $1
Ping
Ping•5d ago
Can I see your auth config?
JROCBABY
JROCBABY•5d ago
Pastebin
Pastebin.com - Burn After Read paste
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
JROCBABY
JROCBABY•5d ago
You can discard the onQuery and generateState, that was some testing stuff I was trying out
Ping
Ping•5d ago
First of all, can you remove the usePlural: true, part of your code? It's redundent (and possibly can cause errors) if you define the schema yourself. And right next to where you had usePlural, please add debugLogs: true, to enable debug logs. Then go through your auth flow which had the error, and show me what the debug logs print in your console. @JROCBABY
JROCBABY
JROCBABY•4d ago
Okay I will, as soon as I get home, thanks for the help 🙏🏻 https://pastebin.com/bQVgzjBE @Ping I removed usePlural and added the debugLogs I'm trying to use OAuth github, since this worked before before I migrated from next auth v5. So what happens is, BetterAuth’s Drizzle adapter is adding a non-UUID id field (5RhgXVViWPC8GTxxxxxxxxxxxxxxxxxx) to the verifications insert, expecting id to be text (per its older schema), but my verifications.id is uuid. The override attempt failed because BetterAuth’s internal logic or adapter is bypassing the custom createVerification method. The error is specific to verifications.id, and other ID-like fields (credentialId, etc.) are unaffected, as they’re correctly text and not involved in the OAuth verification step. Ah it was the generateIds options, I set that to false and everything works like a charm now

Did you find this page helpful?