[GH-ISSUE #2420] Using UUID for drizzle adapter still tries to generate id #9187

Closed
opened 2026-04-13 04:33:49 -05:00 by GiteaMirror · 7 comments
Owner

Originally created by @frankfriberg on GitHub (Apr 24, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2420

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Use schema with drizzle:

export const defaultTimestamps = {
	createdAt: timestamp("created_at").defaultNow().notNull(),
	updatedAt: timestamp("updated_at").$onUpdate(() => new Date()),
};

export const defaultUuid = {
	id: uuid().defaultRandom().primaryKey(),
};

export const users = pgTable("users", {
	...defaultUuid,
	name: text().notNull(),
	email: text().notNull().unique(),
	emailVerified: boolean().notNull(),
	image: text(),
	...defaultTimestamps,
});

export const sessions = pgTable("sessions", {
	...defaultUuid,
	expiresAt: timestamp().notNull(),
	token: uuid().notNull().unique(),
	...defaultTimestamps,
	ipAddress: text(),
	userAgent: text(),
	userId: uuid()
		.notNull()
		.references(() => users.id, { onDelete: "cascade" }),
});

export const accounts = pgTable("accounts", {
	...defaultUuid,
	accountId: text().notNull(),
	providerId: text().notNull(),
	userId: uuid()
		.notNull()
		.references(() => users.id, { onDelete: "cascade" }),
	accessToken: text(),
	refreshToken: text(),
	idToken: text(),
	accessTokenExpiresAt: timestamp(),
	refreshTokenExpiresAt: timestamp(),
	scope: text(),
	password: text(),
	...defaultTimestamps,
});

export const verifications = pgTable("verifications", {
	...defaultUuid,
	identifier: text().notNull(),
	value: text().notNull(),
	expiresAt: timestamp().notNull(),
	...defaultTimestamps,
});

Current vs. Expected behavior

Using 1.2.5 results in expected behaviour of logging in while using 1.2.6 and above gives following error:

SERVER_ERROR:  error: invalid input syntax for type uuid: "vWGhUak5YgR2zw1rdbKr4lErUPQmRssG"
    at /Users/ff/Development/inwi-tanstack/node_modules/pg-pool/index.js:45:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async <anonymous> (/Users/ff/Development/inwi-tanstack/node_modules/src/node-postgres/session.ts:144:19)
    at async withReturning (file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/adapters/drizzle-adapter/index.mjs:49:19)
    at async Object.create (file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/adapters/drizzle-adapter/index.mjs:167:26)
    at async Object.create (file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/shared/better-auth.rSYJCd3o.mjs:388:19)
    at async createWithHooks (file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/shared/better-auth.Bk5IMdhM.mjs:49:71)
    at async Object.createSession (file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/shared/better-auth.Bk5IMdhM.mjs:290:19)
    at async handleOAuthUserInfo (file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/shared/better-auth.CWwVo_61.mjs:1266:19)
    at async file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/shared/better-auth.CWwVo_61.mjs:1942:20
    at async internalHandler (/Users/ff/Development/inwi-tanstack/node_modules/better-call/src/endpoint.ts:332:20)
    at async api.<computed> (file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/api/index.mjs:516:22)
    at async processRequest (/Users/ff/Development/inwi-tanstack/node_modules/better-call/src/router.ts:166:22)
    at async handler (/Users/ff/Development/inwi-tanstack/node_modules/better-call/src/router.ts:187:16)
    at async defaultAPIFileRouteHandler (/Users/ff/Development/inwi-tanstack/node_modules/@tanstack/start-api-routes/src/index.ts:368:10)
    at async eval (/Users/ff/Development/inwi-tanstack/node_modules/@tanstack/start-api-routes/src/index.ts:33:17)
    at async _callHandler (file:///Users/ff/Development/inwi-tanstack/node_modules/h3/dist/index.mjs:1837:16)
    at async file:///Users/ff/Development/inwi-tanstack/node_modules/h3/dist/index.mjs:1978:19
    at async Object.callAsync (file:///Users/ff/Development/inwi-tanstack/node_modules/unctx/dist/index.mjs:72:16)
    at async Server.toNodeHandle (file:///Users/ff/Development/inwi-tanstack/node_modules/h3/dist/index.mjs:2270:7) {
  length: 164,
  severity: 'ERROR',
  code: '22P02',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: "unnamed portal parameter $2 = '...'",
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'uuid.c',
  line: '134',
  routine: 'string_to_uuid'
}

What version of Better Auth are you using?

1.2.7

Provide environment information

- ORM: Drizzle
- DB: Postgres
- Framework: TanStack Start

Which area(s) are affected? (Select all that apply)

Client

Auth config (if applicable)

export const auth = betterAuth({
	database: drizzleAdapter(db, {
		provider: "pg",
		usePlural: true,
	}),
	advanced: {
		database: {
			generateId: false,
			useNumberId: false,
		},
		cookiePrefix: "inwi",
	},
	socialProviders: {
		google: {
			clientId: process.env.GOOGLE_CLIENT_ID,
			clientSecret: process.env.GOOGLE_CLIENT_SECRET,
			redirectURI: process.env.GOOGLE_REDIRECT_URI,
		},
	},
});

Additional context

No response

Originally created by @frankfriberg on GitHub (Apr 24, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2420 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Use schema with drizzle: ```typescript export const defaultTimestamps = { createdAt: timestamp("created_at").defaultNow().notNull(), updatedAt: timestamp("updated_at").$onUpdate(() => new Date()), }; export const defaultUuid = { id: uuid().defaultRandom().primaryKey(), }; export const users = pgTable("users", { ...defaultUuid, name: text().notNull(), email: text().notNull().unique(), emailVerified: boolean().notNull(), image: text(), ...defaultTimestamps, }); export const sessions = pgTable("sessions", { ...defaultUuid, expiresAt: timestamp().notNull(), token: uuid().notNull().unique(), ...defaultTimestamps, ipAddress: text(), userAgent: text(), userId: uuid() .notNull() .references(() => users.id, { onDelete: "cascade" }), }); export const accounts = pgTable("accounts", { ...defaultUuid, accountId: text().notNull(), providerId: text().notNull(), userId: uuid() .notNull() .references(() => users.id, { onDelete: "cascade" }), accessToken: text(), refreshToken: text(), idToken: text(), accessTokenExpiresAt: timestamp(), refreshTokenExpiresAt: timestamp(), scope: text(), password: text(), ...defaultTimestamps, }); export const verifications = pgTable("verifications", { ...defaultUuid, identifier: text().notNull(), value: text().notNull(), expiresAt: timestamp().notNull(), ...defaultTimestamps, }); ``` ### Current vs. Expected behavior Using 1.2.5 results in expected behaviour of logging in while using 1.2.6 and above gives following error: ``` SERVER_ERROR: error: invalid input syntax for type uuid: "vWGhUak5YgR2zw1rdbKr4lErUPQmRssG" at /Users/ff/Development/inwi-tanstack/node_modules/pg-pool/index.js:45:11 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async <anonymous> (/Users/ff/Development/inwi-tanstack/node_modules/src/node-postgres/session.ts:144:19) at async withReturning (file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/adapters/drizzle-adapter/index.mjs:49:19) at async Object.create (file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/adapters/drizzle-adapter/index.mjs:167:26) at async Object.create (file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/shared/better-auth.rSYJCd3o.mjs:388:19) at async createWithHooks (file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/shared/better-auth.Bk5IMdhM.mjs:49:71) at async Object.createSession (file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/shared/better-auth.Bk5IMdhM.mjs:290:19) at async handleOAuthUserInfo (file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/shared/better-auth.CWwVo_61.mjs:1266:19) at async file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/shared/better-auth.CWwVo_61.mjs:1942:20 at async internalHandler (/Users/ff/Development/inwi-tanstack/node_modules/better-call/src/endpoint.ts:332:20) at async api.<computed> (file:///Users/ff/Development/inwi-tanstack/node_modules/better-auth/dist/api/index.mjs:516:22) at async processRequest (/Users/ff/Development/inwi-tanstack/node_modules/better-call/src/router.ts:166:22) at async handler (/Users/ff/Development/inwi-tanstack/node_modules/better-call/src/router.ts:187:16) at async defaultAPIFileRouteHandler (/Users/ff/Development/inwi-tanstack/node_modules/@tanstack/start-api-routes/src/index.ts:368:10) at async eval (/Users/ff/Development/inwi-tanstack/node_modules/@tanstack/start-api-routes/src/index.ts:33:17) at async _callHandler (file:///Users/ff/Development/inwi-tanstack/node_modules/h3/dist/index.mjs:1837:16) at async file:///Users/ff/Development/inwi-tanstack/node_modules/h3/dist/index.mjs:1978:19 at async Object.callAsync (file:///Users/ff/Development/inwi-tanstack/node_modules/unctx/dist/index.mjs:72:16) at async Server.toNodeHandle (file:///Users/ff/Development/inwi-tanstack/node_modules/h3/dist/index.mjs:2270:7) { length: 164, severity: 'ERROR', code: '22P02', detail: undefined, hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: "unnamed portal parameter $2 = '...'", schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'uuid.c', line: '134', routine: 'string_to_uuid' } ``` ### What version of Better Auth are you using? 1.2.7 ### Provide environment information ```bash - ORM: Drizzle - DB: Postgres - Framework: TanStack Start ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", usePlural: true, }), advanced: { database: { generateId: false, useNumberId: false, }, cookiePrefix: "inwi", }, socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, redirectURI: process.env.GOOGLE_REDIRECT_URI, }, }, }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 04:33:49 -05:00
Author
Owner

@Asuniia commented on GitHub (Apr 24, 2025):

Same issue

<!-- gh-comment-id:2827016583 --> @Asuniia commented on GitHub (Apr 24, 2025): Same issue
Author
Owner

@Asuniia commented on GitHub (Apr 24, 2025):

Same issue

Image Image

I have disable auto generate id in better auth config

<!-- gh-comment-id:2827020414 --> @Asuniia commented on GitHub (Apr 24, 2025): > Same issue <img width="748" alt="Image" src="https://github.com/user-attachments/assets/f6cff369-be63-4d5f-8dd2-de7c7f1e8cf8" /> <img width="196" alt="Image" src="https://github.com/user-attachments/assets/1f071e87-7920-45dd-9a5f-64bf86682055" /> I have disable auto generate id in better auth config
Author
Owner

@Asuniia commented on GitHub (Apr 24, 2025):

Same issue

Image Image
I have disable auto generate id in better auth config

Image

Session table

<!-- gh-comment-id:2827024681 --> @Asuniia commented on GitHub (Apr 24, 2025): > > Same issue > > <img alt="Image" width="748" src="https://private-user-images.githubusercontent.com/43389096/436955788-f6cff369-be63-4d5f-8dd2-de7c7f1e8cf8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDU0ODg1NDAsIm5iZiI6MTc0NTQ4ODI0MCwicGF0aCI6Ii80MzM4OTA5Ni80MzY5NTU3ODgtZjZjZmYzNjktYmU2My00ZDVmLThkZDItZGU3YzdmMWU4Y2Y4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA0MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwNDI0VDA5NTA0MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEyNWJkMGMzODU3YmM4ZWM0YTY4NWRiZjM3OWEyMTZmODUyYTVhNzI0MmQ0NTJjMTJhYmQ1ZDY0MTQxMjkxMDEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.UTAcFhnIvZ87RLGXqFaqMaBCGmdf5XIjTzFnw7319jg"> <img alt="Image" width="196" src="https://private-user-images.githubusercontent.com/43389096/436956057-1f071e87-7920-45dd-9a5f-64bf86682055.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDU0ODg1NDAsIm5iZiI6MTc0NTQ4ODI0MCwicGF0aCI6Ii80MzM4OTA5Ni80MzY5NTYwNTctMWYwNzFlODctNzkyMC00NWRkLTlhNWYtNjRiZjg2NjgyMDU1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA0MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwNDI0VDA5NTA0MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU4MzI5M2RmZGJiYmEwMTk5M2Y3OGMxMTliZjNmNzk4ZDM1NmE0NDM2M2NlYjQwOTliN2QyM2RjZWZkNWZiYmImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.u34Qyzz-Ztzc4Cc7KDXQ0GUsNAFylW_ESvH9hU4mwV0"> > I have disable auto generate id in better auth config <img width="1284" alt="Image" src="https://github.com/user-attachments/assets/f2cb88f2-8505-45d5-86ae-f4349b1ee004" /> Session table
Author
Owner

@ping-maxwell commented on GitHub (Apr 24, 2025):

@Asuniia You need to define it under advanced.database.generateId

<!-- gh-comment-id:2827063389 --> @ping-maxwell commented on GitHub (Apr 24, 2025): @Asuniia You need to define it under `advanced.database.generateId`
Author
Owner

@ping-maxwell commented on GitHub (Apr 24, 2025):

@frankfriberg I'm still investigating, I'll get back to you if I find anything.

<!-- gh-comment-id:2827065351 --> @ping-maxwell commented on GitHub (Apr 24, 2025): @frankfriberg I'm still investigating, I'll get back to you if I find anything.
Author
Owner

@ping-maxwell commented on GitHub (Apr 24, 2025):

@frankfriberg I'm testing on my end and it seems to be working.

Can you enable debug logs?

drizzleAdapter(db, {debugLogs: true})

We should look for something like this:

Image

Notice that on the 2/4, the id is undefined. This is how it should be once disableId is enabled like I have.

Once you find it, can you send a screenshot? Thanks

<!-- gh-comment-id:2827080002 --> @ping-maxwell commented on GitHub (Apr 24, 2025): @frankfriberg I'm testing on my end and it seems to be working. Can you enable debug logs? ```ts drizzleAdapter(db, {debugLogs: true}) ``` We should look for something like this: <img width="1139" alt="Image" src="https://github.com/user-attachments/assets/1ee67a10-e0c1-4a8a-b592-739f9e028938" /> Notice that on the 2/4, the `id` is undefined. This is how it should be once disableId is enabled like I have. Once you find it, can you send a screenshot? Thanks
Author
Owner

@frankfriberg commented on GitHub (Apr 24, 2025):

@ping-maxwell sorry for the inconvenience, apparently I set the token to be uuid for sessions:

export const sessions = pgTable("sessions", {
	...defaultUuid,
	expiresAt: timestamp().notNull(),
	token: uuid().notNull().unique(),
	...defaultTimestamps,
	ipAddress: text(),
	userAgent: text(),
	userId: uuid()
		.notNull()
		.references(() => users.id, { onDelete: "cascade" }),
});

The debug flag helped pinpoint it, thanks for the help! 🙏🏻

<!-- gh-comment-id:2827446454 --> @frankfriberg commented on GitHub (Apr 24, 2025): @ping-maxwell sorry for the inconvenience, apparently I set the token to be `uuid` for sessions: ```typescript export const sessions = pgTable("sessions", { ...defaultUuid, expiresAt: timestamp().notNull(), token: uuid().notNull().unique(), ...defaultTimestamps, ipAddress: text(), userAgent: text(), userId: uuid() .notNull() .references(() => users.id, { onDelete: "cascade" }), }); ``` The debug flag helped pinpoint it, thanks for the help! 🙏🏻
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9187