[GH-ISSUE #3450] Prisma Adapter Passes String User IDs Instead of Integers #18237

Closed
opened 2026-04-15 16:38:24 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @exploriter on GitHub (Jul 18, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3450

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Set up Prisma schema with integer user IDs
  2. Configure Better Auth with generateId: false
  3. Attempt Google OAuth sign-in
  4. Observe Account creation failure (Argument userId: Invalid value provided. Expected Int, provided String.)

Current vs. Expected behavior

When generateId: false is set, Better Auth should:

  1. Create User with integer ID (auto-increment)
  2. Create Account with integer userId referencing the User

Actual Behavior

  1. User is created successfully with integer ID 1
  2. Account creation fails with error: Argument userId: Invalid value provided. Expected Int, provided String.

What version of Better Auth are you using?

1.2.12

Provide environment information

- Better Auth version: 1.2.12
- Prisma version: 6.12.0
- Database: PostgreSQL
- Framework: Next.js 15.4.1

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

Backend

Auth config (if applicable)


Additional context

Prisma Schema:

  model User {
    id            Int               @id @default(autoincrement())
    email         String            @unique
    name          String?
    image         String?
    accounts      Account[]
    sessions      Session[]
    // ... other fields
  }

  model Account {
    id                    String    @id @default(cuid())
    userId                Int       @map("user_id")
    accountId             String    @map("account_id")
    providerId            String    @map("provider_id")
    // ... other fields
    
    user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  }

auth:

import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { PrismaClient } from "@/generated/prisma";

const prisma = new PrismaClient();

export const auth = betterAuth({
	database: prismaAdapter(prisma, {
		provider: "postgresql",
	}),
	advanced: {
		database: {
			generateId: false,
		},
	},
	socialProviders: {
		google: {
			clientId: process.env.GOOGLE_CLIENT_ID as string,
			clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
		},
	},
	user: {
		additionalFields: {
			role: {
				type: "string",
				required: true,
				defaultValue: "FREE",
				input: false,
			},
		},
	},
});

Error Details:

Invalid `prisma.account.create()` invocation:
{
  data: {
    accountId: "102376002342342417678",
    providerId: "google",
    userId: "1",  // ← STRING instead of INTEGER
    // ... other fields
  }
}
Argument `userId`: Invalid value provided. Expected Int, provided String.
Originally created by @exploriter on GitHub (Jul 18, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3450 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Set up Prisma schema with integer user IDs 2. Configure Better Auth with generateId: false 3. Attempt Google OAuth sign-in 4. Observe Account creation failure (Argument `userId`: Invalid value provided. Expected Int, provided String.) ### Current vs. Expected behavior When generateId: false is set, Better Auth should: 1. Create User with integer ID (auto-increment) 2. Create Account with integer userId referencing the User Actual Behavior 1. User is created successfully with integer ID 1 2. Account creation fails with error: Argument userId: Invalid value provided. Expected Int, provided String. ### What version of Better Auth are you using? 1.2.12 ### Provide environment information ```bash - Better Auth version: 1.2.12 - Prisma version: 6.12.0 - Database: PostgreSQL - Framework: Next.js 15.4.1 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript ``` ### Additional context Prisma Schema: ```prisma model User { id Int @id @default(autoincrement()) email String @unique name String? image String? accounts Account[] sessions Session[] // ... other fields } model Account { id String @id @default(cuid()) userId Int @map("user_id") accountId String @map("account_id") providerId String @map("provider_id") // ... other fields user User @relation(fields: [userId], references: [id], onDelete: Cascade) } ``` auth: ```ts import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import { PrismaClient } from "@/generated/prisma"; const prisma = new PrismaClient(); export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql", }), advanced: { database: { generateId: false, }, }, socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, }, }, user: { additionalFields: { role: { type: "string", required: true, defaultValue: "FREE", input: false, }, }, }, }); ``` Error Details: ``` Invalid `prisma.account.create()` invocation: { data: { accountId: "102376002342342417678", providerId: "google", userId: "1", // ← STRING instead of INTEGER // ... other fields } } Argument `userId`: Invalid value provided. Expected Int, provided String. ```
GiteaMirror added the lockedbug labels 2026-04-15 16:38:24 -05:00
Author
Owner

@exploriter commented on GitHub (Jul 18, 2025):

Good lord. That took forever to find this hidden flag: https://github.com/better-auth/better-auth/issues/2349#issuecomment-2827599530

<!-- gh-comment-id:3090364270 --> @exploriter commented on GitHub (Jul 18, 2025): Good lord. That took forever to find this hidden flag: https://github.com/better-auth/better-auth/issues/2349#issuecomment-2827599530
Author
Owner

@itxtoledo commented on GitHub (Dec 22, 2025):

If I add that "hidden flag" I have this error:

# SERVER_ERROR:  PrismaClientValidationError: 
Invalid `adapterInstance.create()` invocation in
/Users/myuser/Projects/amplify-digital/amped-bio-new/node_modules/.pnpm/@better-auth+core@1.4.7_@better-auth+utils@0.3.0_@better-fetch+fetch@1.1.21_better-call@1.1.5_ysziofpe4uzylpi7lyyyenv3oi/node_modules/@better-auth/core/dist/db/adapter/index.mjs:638:38

  635   model,
  636   data
  637 });638 const res = await adapterInstance.create({
        data: {
          identifier: "o4j3mAngA-Y6jaPoUIXmzY5gPsCVphb7",
          value: "REDACTED,
          expiresAt: new Date("2025-12-22T19:27:18.615Z"),
          createdAt: new Date("2025-12-22T19:17:18.615Z"),
          updatedAt: new Date("2025-12-22T19:17:18.615Z"),
      +   id: String
        },
        select: undefined
      })

Argument `id` is missing.
<!-- gh-comment-id:3683799080 --> @itxtoledo commented on GitHub (Dec 22, 2025): If I add that "hidden flag" I have this error: ```bash # SERVER_ERROR: PrismaClientValidationError: Invalid `adapterInstance.create()` invocation in /Users/myuser/Projects/amplify-digital/amped-bio-new/node_modules/.pnpm/@better-auth+core@1.4.7_@better-auth+utils@0.3.0_@better-fetch+fetch@1.1.21_better-call@1.1.5_ysziofpe4uzylpi7lyyyenv3oi/node_modules/@better-auth/core/dist/db/adapter/index.mjs:638:38 635 model, 636 data 637 }); → 638 const res = await adapterInstance.create({ data: { identifier: "o4j3mAngA-Y6jaPoUIXmzY5gPsCVphb7", value: "REDACTED, expiresAt: new Date("2025-12-22T19:27:18.615Z"), createdAt: new Date("2025-12-22T19:17:18.615Z"), updatedAt: new Date("2025-12-22T19:17:18.615Z"), + id: String }, select: undefined }) Argument `id` is missing. ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18237