[GH-ISSUE #1901] Next.js w/ Prisma and custom model names throwing error "BetterAuthError: Model verification does not exist in the database." #8967

Closed
opened 2026-04-13 04:12:50 -05:00 by GiteaMirror · 7 comments
Owner

Originally created by @sameerxanand on GitHub (Mar 20, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1901

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Auth configuration:

import { PrismaClient } from "@prisma/client";
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { nextCookies } from "better-auth/next-js";

const prisma = new PrismaClient();

export const auth = betterAuth({
  plugins: [nextCookies()],
  user: {
    modelName: "users",
  },
  session: {
    modelName: "sessions",
  },
  account: {
    modelName: "accounts",
    accountLinking: {
      enabled: true,
      trustedProviders: ["google", "apple"],
      allowDifferentEmails: false,
    },
  },
  verification: {
    modelName: "verifications",
  },
  database: prismaAdapter(prisma, {
    provider: "postgresql",
  }),
  socialProviders: {
    google: {
      clientId: process.env.AUTH_GOOGLE_ID!,
      clientSecret: process.env.AUTH_GOOGLE_SECRET!,
    },
    apple: {
      clientId: process.env.AUTH_APPLE_ID!,
      clientSecret: process.env.AUTH_APPLE_SECRET!,
    },
  },
});

Prisma schema:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id            String    @id
  name          String
  email         String
  emailVerified Boolean
  image         String?
  createdAt     DateTime
  updatedAt     DateTime
  sessions      Session[]
  accounts      Account[]

  @@unique([email])
  @@map("users")
}

model Session {
  id        String   @id
  expiresAt DateTime
  token     String
  createdAt DateTime
  updatedAt DateTime
  ipAddress String?
  userAgent String?
  userId    String
  user      User     @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([token])
  @@map("sessions")
}

model Account {
  id                    String    @id
  accountId             String
  providerId            String
  userId                String
  user                  User      @relation(fields: [userId], references: [id], onDelete: Cascade)
  accessToken           String?
  refreshToken          String?
  idToken               String?
  accessTokenExpiresAt  DateTime?
  refreshTokenExpiresAt DateTime?
  scope                 String?
  password              String?
  createdAt             DateTime
  updatedAt             DateTime

  @@map("accounts")
}

model Verification {
  id         String    @id
  identifier String
  value      String
  expiresAt  DateTime
  createdAt  DateTime?
  updatedAt  DateTime?

  @@map("verifications")
}

Server action:

<form
  action={async () => {
    "use server";
    await auth.api.signInSocial({
      body: {
        provider: "google",
      },
    });
  }}
  className="w-full"
>
  <Button
    type="submit"
    variant="outline"
    className="w-full cursor-pointer space-x-2"
  >
    <SiGoogle className="size-4" />
    <span>Google</span>
  </Button>
</form>

Current vs. Expected behavior

Clicking the "Google" button to trigger the sign-in action throws the error:

BetterAuthError: Model verification does not exist in the database. If you haven't generated the Prisma client, you need to run 'npx prisma generate'

I've already ran the migrations and generated the Prisma client. The auth configuration seems to be ignoring the custom modelName I set.

What version of Better Auth are you using?

1.2.4

Provide environment information

- OS Mac 15.1
- next 15.3.0-canary.6

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

Backend

Auth config (if applicable)

import { PrismaClient } from "@prisma/client";
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { nextCookies } from "better-auth/next-js";

const prisma = new PrismaClient();

export const auth = betterAuth({
  plugins: [nextCookies()],
  user: {
    modelName: "users",
  },
  session: {
    modelName: "sessions",
  },
  account: {
    modelName: "accounts",
    accountLinking: {
      enabled: true,
      trustedProviders: ["google", "apple"],
      allowDifferentEmails: false,
    },
  },
  verification: {
    modelName: "verifications",
  },
  database: prismaAdapter(prisma, {
    provider: "postgresql",
  }),
  socialProviders: {
    google: {
      clientId: process.env.AUTH_GOOGLE_ID!,
      clientSecret: process.env.AUTH_GOOGLE_SECRET!,
    },
    apple: {
      clientId: process.env.AUTH_APPLE_ID!,
      clientSecret: process.env.AUTH_APPLE_SECRET!,
    },
  },
});

Additional context

No response

Originally created by @sameerxanand on GitHub (Mar 20, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1901 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Auth configuration: ```ts import { PrismaClient } from "@prisma/client"; import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import { nextCookies } from "better-auth/next-js"; const prisma = new PrismaClient(); export const auth = betterAuth({ plugins: [nextCookies()], user: { modelName: "users", }, session: { modelName: "sessions", }, account: { modelName: "accounts", accountLinking: { enabled: true, trustedProviders: ["google", "apple"], allowDifferentEmails: false, }, }, verification: { modelName: "verifications", }, database: prismaAdapter(prisma, { provider: "postgresql", }), socialProviders: { google: { clientId: process.env.AUTH_GOOGLE_ID!, clientSecret: process.env.AUTH_GOOGLE_SECRET!, }, apple: { clientId: process.env.AUTH_APPLE_ID!, clientSecret: process.env.AUTH_APPLE_SECRET!, }, }, }); ``` Prisma schema: ```ts // This is your Prisma schema file, // learn more about it in the docs: https://pris.ly/d/prisma-schema generator client { provider = "prisma-client-js" } datasource db { provider = "postgresql" url = env("DATABASE_URL") } model User { id String @id name String email String emailVerified Boolean image String? createdAt DateTime updatedAt DateTime sessions Session[] accounts Account[] @@unique([email]) @@map("users") } model Session { id String @id expiresAt DateTime token String createdAt DateTime updatedAt DateTime ipAddress String? userAgent String? userId String user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@unique([token]) @@map("sessions") } model Account { id String @id accountId String providerId String userId String user User @relation(fields: [userId], references: [id], onDelete: Cascade) accessToken String? refreshToken String? idToken String? accessTokenExpiresAt DateTime? refreshTokenExpiresAt DateTime? scope String? password String? createdAt DateTime updatedAt DateTime @@map("accounts") } model Verification { id String @id identifier String value String expiresAt DateTime createdAt DateTime? updatedAt DateTime? @@map("verifications") } ``` Server action: ```tsx <form action={async () => { "use server"; await auth.api.signInSocial({ body: { provider: "google", }, }); }} className="w-full" > <Button type="submit" variant="outline" className="w-full cursor-pointer space-x-2" > <SiGoogle className="size-4" /> <span>Google</span> </Button> </form> ``` ### Current vs. Expected behavior Clicking the "Google" button to trigger the sign-in action throws the error: ``` BetterAuthError: Model verification does not exist in the database. If you haven't generated the Prisma client, you need to run 'npx prisma generate' ``` I've already ran the migrations and generated the Prisma client. The auth configuration seems to be ignoring the custom `modelName` I set. ### What version of Better Auth are you using? 1.2.4 ### Provide environment information ```bash - OS Mac 15.1 - next 15.3.0-canary.6 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { PrismaClient } from "@prisma/client"; import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import { nextCookies } from "better-auth/next-js"; const prisma = new PrismaClient(); export const auth = betterAuth({ plugins: [nextCookies()], user: { modelName: "users", }, session: { modelName: "sessions", }, account: { modelName: "accounts", accountLinking: { enabled: true, trustedProviders: ["google", "apple"], allowDifferentEmails: false, }, }, verification: { modelName: "verifications", }, database: prismaAdapter(prisma, { provider: "postgresql", }), socialProviders: { google: { clientId: process.env.AUTH_GOOGLE_ID!, clientSecret: process.env.AUTH_GOOGLE_SECRET!, }, apple: { clientId: process.env.AUTH_APPLE_ID!, clientSecret: process.env.AUTH_APPLE_SECRET!, }, }, }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 04:12:50 -05:00
Author
Owner

@sameerxanand commented on GitHub (Mar 20, 2025):

This is not just happening with the verifications model. This seems to be happening with all of them. Another example with the sessions table:

Image

<!-- gh-comment-id:2741433716 --> @sameerxanand commented on GitHub (Mar 20, 2025): This is not just happening with the `verifications` model. This seems to be happening with all of them. Another example with the `sessions` table: ![Image](https://github.com/user-attachments/assets/31e1a714-35a0-4e17-90ab-abc951f42c77)
Author
Owner

@sameerxanand commented on GitHub (Mar 21, 2025):

I'm also facing this same kind of error with users table, here is the error message i'm getting

Error {
error: [Error [BetterAuthError]: [# Drizzle Adapter]: The model "user" was not found in the schema object. Please pass the schema directly to the adapter options.] {
cause: undefined
}
}

here is my auth.ts file

import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "@/db/drizzle";
import { nextCookies } from "better-auth/next-js";
import { sendEmail } from "@/actions/helpers";
import { admin as adminPlugin, openAPI } from "better-auth/plugins";
import { admin, agent, user } from "./permissions";

export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
}),
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
sendResetPassword: async ({ user, url }) => {
await sendEmail({
to: user.email,
subject: "Reset your password",
text: Click the link to reset your password: ${url},
});
},
},
plugins: [
nextCookies(),
adminPlugin({
defaultBanReason: "No reason",
roles: {
admin,
agent,
user,
},
}),
openAPI(),
],
emailVerification: {
sendOnSignUp: true,
sendVerificationEmail: async ({ user, url }) => {
await sendEmail({
to: user.email,
subject: "Verify your email address",
text: Click the link to verify your email: ${url},
});
},
},
});

Your issue is different. You're not passing your schema in the drizzleAdapter()

<!-- gh-comment-id:2743402111 --> @sameerxanand commented on GitHub (Mar 21, 2025): > I'm also facing this same kind of error with users table, here is the error message i'm getting > > Error { > error: [Error [BetterAuthError]: [# Drizzle Adapter]: The model "user" was not found in the schema object. Please pass the schema directly to the adapter options.] { > cause: undefined > } > } > > here is my auth.ts file > > import { betterAuth } from "better-auth"; > import { drizzleAdapter } from "better-auth/adapters/drizzle"; > import { db } from "@/db/drizzle"; > import { nextCookies } from "better-auth/next-js"; > import { sendEmail } from "@/actions/helpers"; > import { admin as adminPlugin, openAPI } from "better-auth/plugins"; > import { admin, agent, user } from "./permissions"; > > export const auth = betterAuth({ > database: drizzleAdapter(db, { > provider: "pg", > }), > emailAndPassword: { > enabled: true, > requireEmailVerification: true, > sendResetPassword: async ({ user, url }) => { > await sendEmail({ > to: user.email, > subject: "Reset your password", > text: `Click the link to reset your password: ${url}`, > }); > }, > }, > plugins: [ > nextCookies(), > adminPlugin({ > defaultBanReason: "No reason", > roles: { > admin, > agent, > user, > }, > }), > openAPI(), > ], > emailVerification: { > sendOnSignUp: true, > sendVerificationEmail: async ({ user, url }) => { > await sendEmail({ > to: user.email, > subject: "Verify your email address", > text: `Click the link to verify your email: ${url}`, > }); > }, > }, > }); > Your issue is different. You're not passing your schema in the `drizzleAdapter()`
Author
Owner

@n10ty commented on GitHub (Apr 25, 2025):

Try to set your better auth modelName same as a Prisma model name, not a db table:

verification: {
    modelName: "Verification",
  },
<!-- gh-comment-id:2830028860 --> @n10ty commented on GitHub (Apr 25, 2025): Try to set your better auth modelName same as a Prisma model name, not a db table: ``` verification: { modelName: "Verification", }, ```
Author
Owner

@Kinfe123 commented on GitHub (May 3, 2025):

@sameerxanand is this still an issue ? i dont think this is an issue here from better auth. make sure to do the necessary migration and generation with the right config.

<!-- gh-comment-id:2848631951 --> @Kinfe123 commented on GitHub (May 3, 2025): @sameerxanand is this still an issue ? i dont think this is an issue here from better auth. make sure to do the necessary migration and generation with the right config.
Author
Owner

@sameerxanand commented on GitHub (May 3, 2025):

@sameerxanand is this still an issue ? i dont think this is an issue here from better auth. make sure to do the necessary migration and generation with the right config.

I will retest this and let you know.

<!-- gh-comment-id:2848709412 --> @sameerxanand commented on GitHub (May 3, 2025): > @sameerxanand is this still an issue ? i dont think this is an issue here from better auth. make sure to do the necessary migration and generation with the right config. I will retest this and let you know.
Author
Owner

@Kinfe123 commented on GitHub (May 4, 2025):

make sure to tag me here if the issue persists. for now i have to close it.

<!-- gh-comment-id:2849298652 --> @Kinfe123 commented on GitHub (May 4, 2025): make sure to tag me here if the issue persists. for now i have to close it.
Author
Owner

@RSickenberg commented on GitHub (Oct 27, 2025):

@Kinfe123 I also have this issue with Github provider also with Prisma.

<!-- gh-comment-id:3451280234 --> @RSickenberg commented on GitHub (Oct 27, 2025): @Kinfe123 I also have this issue with Github provider also with Prisma.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8967