[GH-ISSUE #1939] Next.js w/ Prisma fails to update the session state #26298

Closed
opened 2026-04-17 16:48:11 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @phyziyx on GitHub (Mar 22, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1939

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

The invalid prisma.session.update() invocation error occurs when the application attempts to update the session state specifically when using Prisma with either MySQL or Postgres with the Prisma adaptor plugin.

The Session model is

model Session {
  id             String   @id @default(uuid())
  userId         String
  token          String
  expiresAt      DateTime
  ipAddress      String?
  userAgent      String?
  impersonatedBy String?

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  User User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

Current vs. Expected behavior

It should update the session without throwing an error.

What version of Better Auth are you using?

1.2.4

Provide environment information

Not Applicable

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

Documentation, Package, Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  database: prismaAdapter(prisma, {
    provider: "mysql",
  }),
  user: {
    modelName: "User",
  },
  session: {
    modelName: "Session",
    cookieCache: {
      enabled: true,
      maxAge: 5 * 60, // Cache duration in seconds
    },
  },
  verification: {
    modelName: "Verification",
  },
  plugins: [nextCookies(), admin(), openAPI()],
  emailAndPassword: {
    enabled: true,
    minPasswordLength: 8,
    autoSignIn: true,
  },
});

Additional context

No response

Originally created by @phyziyx on GitHub (Mar 22, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1939 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce The invalid `prisma.session.update()` invocation error occurs when the application attempts to update the session state specifically when using Prisma with either MySQL or Postgres with the Prisma adaptor plugin. The Session model is ```js model Session { id String @id @default(uuid()) userId String token String expiresAt DateTime ipAddress String? userAgent String? impersonatedBy String? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt User User @relation(fields: [userId], references: [id], onDelete: Cascade) } ``` ### Current vs. Expected behavior It should update the session without throwing an error. ### What version of Better Auth are you using? 1.2.4 ### Provide environment information ```bash Not Applicable ``` ### Which area(s) are affected? (Select all that apply) Documentation, Package, Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "mysql", }), user: { modelName: "User", }, session: { modelName: "Session", cookieCache: { enabled: true, maxAge: 5 * 60, // Cache duration in seconds }, }, verification: { modelName: "Verification", }, plugins: [nextCookies(), admin(), openAPI()], emailAndPassword: { enabled: true, minPasswordLength: 8, autoSignIn: true, }, }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-17 16:48:12 -05:00
Author
Owner

@Bekacru commented on GitHub (Mar 23, 2025):

mark token as a unique field @unique

<!-- gh-comment-id:2746364115 --> @Bekacru commented on GitHub (Mar 23, 2025): mark `token` as a unique field `@unique`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#26298