[GH-ISSUE #6728] Nest backend setup but sign-up in email failed: Invalid invocation #19234

Open
opened 2026-04-15 18:05:01 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @Arutowk on GitHub (Dec 13, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6728

Originally assigned to: @Paola3stefania on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

setup background:

  1. fllow NestJS Integration guide install @thallesp/nestjs-better-auth
  2. edit auth.ts\app.module.ts\main.ts config
  3. use openAPI to test request [POST]'http://localhost:3001/api/auth/sign-up/email'
  4. end with error
  5. try to edit schema.prisma, change User model @@map() did not work

Current vs. Expected behavior

Current Error:
ERROR [Better Auth]: PrismaClientKnownRequestError PrismaClientKnownRequestError:
Invalid prisma.user.findFirst() invocation:
at qr.handleRequestError (E:\code\next-nest\node_modules.pnpm@prisma+client@7.1.0_prisma_a0886acc89372f6f581245297505cbe3\node_modules@prisma\client\src\runtime\RequestHandler.ts:228:13)
at qr.handleAndLogRequestError (E:\code\next-nest\node_modules.pnpm@prisma+client@7.1.0_prisma_a0886acc89372f6f581245297505cbe3\node_modules@prisma\client\src\runtime\RequestHandler.ts:174:12)
at qr.request (E:\code\next-nest\node_modules.pnpm@prisma+client@7.1.0_prisma_a0886acc89372f6f581245297505cbe3\node_modules@prisma\client\src\runtime\RequestHandler.ts:143:12)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async a (E:\code\next-nest\node_modules.pnpm@prisma+client@7.1.0_prisma_a0886acc89372f6f581245297505cbe3\node_modules@prisma\client\src\runtime\getPrismaClient.ts:805:24)
at async Object.findOne (file:///E:/code/next-nest/node_modules/.pnpm/better-auth@1.4.6_next@16.0_a7e66e2bac9a6d9c618582a361547e94/node_modules/better-auth/dist/adapters/prisma-adapter/index.mjs:110:18)
at async Object.findOne (file:///E:/code/next-nest/node_modules/.pnpm/@better-auth+core@1.4.6_@be_414df9a6872f19f7a4a85d1e0b923f9d/node_modules/@better-auth/core/dist/db/adapter/index.mjs:749:16)
at async Object.findUserByEmail (file:///E:/code/next-nest/node_modules/.pnpm/better-auth@1.4.6_next@16.0_a7e66e2bac9a6d9c618582a361547e94/node_modules/better-auth/dist/get-migration-CDvYpogu.mjs:614:19)
at async file:///E:/code/next-nest/node_modules/.pnpm/better-auth@1.4.6_next@16.0_a7e66e2bac9a6d9c618582a361547e94/node_modules/better-auth/dist/api-D0cF0fk5.mjs:2327:8
at async internalHandler (E:\code\next-nest\node_modules.pnpm\better-call@1.1.5_zod@4.1.13\node_modules\better-call\src\endpoint.ts:507:20) {
code: 'ECONNREFUSED',
meta: { modelName: 'User' },
clientVersion: '7.1.0'
}

Expected behavior:
creat a user successful with email method

What version of Better Auth are you using?

1.4.6

System info

📊 Better Auth System Information

==================================================

🖥️  System Information:
  platform: win32
  arch: x64
  version: Windows 10 Home

📦 Node.js:
  version: v24.11.0
  env: development

📦 Package Manager:
  name: pnpm
  version: 10.11.0

💾 Database Clients:
  name: pg
  version: ^8.16.3
  name: @prisma/client
  version: ^7.1.0

🔐 Better Auth:
  Version: ^1.4.6
  Configuration:
    session:
      cookieCache:
        enabled: true
        maxAge: 300
    emailAndPassword:
      enabled: true
      minPasswordLength: 4
      maxPasswordLength: 32
    socialProviders:
      github:
        clientId: [REDACTED]
        clientSecret: [REDACTED]
      google:
        clientId: [REDACTED]
        clientSecret: [REDACTED]
    baseURL: http://localhost:3001
    trustedOrigins: http://localhost
    plugins: name: open-api
config:
  id: open-api
  endpoints:
    {}
    advanced:
      database:
        generateId: false
      defaultCookieAttributes:
        sameSite: none
        secure: true
        httpOnly: true

==================================================

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @Arutowk on GitHub (Dec 13, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6728 Originally assigned to: @Paola3stefania on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce setup background: 1. fllow NestJS Integration guide install @thallesp/nestjs-better-auth 2. edit auth.ts\app.module.ts\main.ts config 3. use openAPI to test request [POST]'http://localhost:3001/api/auth/sign-up/email' 4. end with error 5. try to edit schema.prisma, change User model @@map() did not work ### Current vs. Expected behavior Current Error: ERROR [Better Auth]: PrismaClientKnownRequestError PrismaClientKnownRequestError: Invalid `prisma.user.findFirst()` invocation: at qr.handleRequestError (E:\code\next-nest\node_modules\.pnpm\@prisma+client@7.1.0_prisma_a0886acc89372f6f581245297505cbe3\node_modules\@prisma\client\src\runtime\RequestHandler.ts:228:13) at qr.handleAndLogRequestError (E:\code\next-nest\node_modules\.pnpm\@prisma+client@7.1.0_prisma_a0886acc89372f6f581245297505cbe3\node_modules\@prisma\client\src\runtime\RequestHandler.ts:174:12) at qr.request (E:\code\next-nest\node_modules\.pnpm\@prisma+client@7.1.0_prisma_a0886acc89372f6f581245297505cbe3\node_modules\@prisma\client\src\runtime\RequestHandler.ts:143:12) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async a (E:\code\next-nest\node_modules\.pnpm\@prisma+client@7.1.0_prisma_a0886acc89372f6f581245297505cbe3\node_modules\@prisma\client\src\runtime\getPrismaClient.ts:805:24) at async Object.findOne (file:///E:/code/next-nest/node_modules/.pnpm/better-auth@1.4.6_next@16.0_a7e66e2bac9a6d9c618582a361547e94/node_modules/better-auth/dist/adapters/prisma-adapter/index.mjs:110:18) at async Object.findOne (file:///E:/code/next-nest/node_modules/.pnpm/@better-auth+core@1.4.6_@be_414df9a6872f19f7a4a85d1e0b923f9d/node_modules/@better-auth/core/dist/db/adapter/index.mjs:749:16) at async Object.findUserByEmail (file:///E:/code/next-nest/node_modules/.pnpm/better-auth@1.4.6_next@16.0_a7e66e2bac9a6d9c618582a361547e94/node_modules/better-auth/dist/get-migration-CDvYpogu.mjs:614:19) at async file:///E:/code/next-nest/node_modules/.pnpm/better-auth@1.4.6_next@16.0_a7e66e2bac9a6d9c618582a361547e94/node_modules/better-auth/dist/api-D0cF0fk5.mjs:2327:8 at async internalHandler (E:\code\next-nest\node_modules\.pnpm\better-call@1.1.5_zod@4.1.13\node_modules\better-call\src\endpoint.ts:507:20) { code: 'ECONNREFUSED', meta: { modelName: 'User' }, clientVersion: '7.1.0' } Expected behavior: creat a user successful with email method ### What version of Better Auth are you using? 1.4.6 ### System info ```bash 📊 Better Auth System Information ================================================== 🖥️ System Information: platform: win32 arch: x64 version: Windows 10 Home 📦 Node.js: version: v24.11.0 env: development 📦 Package Manager: name: pnpm version: 10.11.0 💾 Database Clients: name: pg version: ^8.16.3 name: @prisma/client version: ^7.1.0 🔐 Better Auth: Version: ^1.4.6 Configuration: session: cookieCache: enabled: true maxAge: 300 emailAndPassword: enabled: true minPasswordLength: 4 maxPasswordLength: 32 socialProviders: github: clientId: [REDACTED] clientSecret: [REDACTED] google: clientId: [REDACTED] clientSecret: [REDACTED] baseURL: http://localhost:3001 trustedOrigins: http://localhost plugins: name: open-api config: id: open-api endpoints: {} advanced: database: generateId: false defaultCookieAttributes: sameSite: none secure: true httpOnly: true ================================================== ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the platformcredentialsdatabasebug labels 2026-04-15 18:05:02 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Dec 13, 2025):

Hi @Arutowk! I'm Dosu and I’m helping the better-auth team.

The "Invalid invocation" error with prisma.user.findFirst() is usually caused by a mismatch between your Prisma schema and what Better Auth expects, or by database connectivity issues. For Better Auth to work with Prisma, your User model in schema.prisma should have specific fields and mappings, including id, name, email, emailVerified (as a Boolean), and relations to Session, Account, and TwoFactor models, plus unique constraints and @@map("user") for table mapping. You can see the exact expected schema here.

Common causes for this error:

  • The Prisma User model is missing required fields or has incorrect types (e.g., emailVerified as DateTime? instead of Boolean) source.
  • The User model/table name or mapping (@@map) does not match what Better Auth expects.
  • There is a password field in the User model, which should be removed—Better Auth handles passwords via the Account model's credentials property source.
  • The database schema and Prisma client are out of sync (run prisma migrate and prisma generate after any changes).
  • Prisma strictUndefinedChecks is enabled and undefined values are not filtered out in plugin-added fields; you may need to use a workaround with Prisma.skip source.
  • The database is not running or accessible from your backend.

For NestJS, make sure global body parsing is disabled for Better Auth routes and use custom middleware if needed source.

If you share your current schema.prisma User, Account, Session, and related models, I can help spot any mismatches. Otherwise, check your schema against the reference, remove any password fields, and ensure you run migrations and generate the Prisma client after changes.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3649114483 --> @dosubot[bot] commented on GitHub (Dec 13, 2025): <!-- Greeting --> Hi @Arutowk! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The "Invalid invocation" error with `prisma.user.findFirst()` is usually caused by a mismatch between your Prisma schema and what Better Auth expects, or by database connectivity issues. For Better Auth to work with Prisma, your `User` model in `schema.prisma` should have specific fields and mappings, including `id`, `name`, `email`, `emailVerified` (as a Boolean), and relations to `Session`, `Account`, and `TwoFactor` models, plus unique constraints and `@@map("user")` for table mapping. You can see the exact expected schema [here](https://github.com/better-auth/better-auth/blob/c1656d0d70f845d1b380db94749bafb4c90596f8/packages/cli/test/__snapshots__/schema.prisma#L11-L89). Common causes for this error: - The Prisma User model is missing required fields or has incorrect types (e.g., `emailVerified` as `DateTime?` instead of `Boolean`) [source](https://github.com/better-auth/better-auth/issues/3469). - The User model/table name or mapping (`@@map`) does not match what Better Auth expects. - There is a `password` field in the User model, which should be removed—Better Auth handles passwords via the Account model's `credentials` property [source](https://github.com/better-auth/better-auth/discussions/6100). - The database schema and Prisma client are out of sync (run `prisma migrate` and `prisma generate` after any changes). - Prisma strictUndefinedChecks is enabled and undefined values are not filtered out in plugin-added fields; you may need to use a workaround with `Prisma.skip` [source](https://github.com/better-auth/better-auth/issues/4341#issuecomment-3241435692). - The database is not running or accessible from your backend. For NestJS, make sure global body parsing is disabled for Better Auth routes and use custom middleware if needed [source](https://github.com/better-auth/better-auth/issues/171). If you share your current `schema.prisma` User, Account, Session, and related models, I can help spot any mismatches. Otherwise, check your schema against the [reference](https://github.com/better-auth/better-auth/blob/c1656d0d70f845d1b380db94749bafb4c90596f8/packages/cli/test/__snapshots__/schema.prisma#L11-L89), remove any `password` fields, and ensure you run migrations and generate the Prisma client after changes. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/9a8ba262-b959-4aec-8da4-bf046f63c583?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/9a8ba262-b959-4aec-8da4-bf046f63c583?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/9a8ba262-b959-4aec-8da4-bf046f63c583?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/9a8ba262-b959-4aec-8da4-bf046f63c583?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/9a8ba262-b959-4aec-8da4-bf046f63c583?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/9a8ba262-b959-4aec-8da4-bf046f63c583?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/9a8ba262-b959-4aec-8da4-bf046f63c583?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20%22Invalid%20invocation%22%20error%20with%20%60prisma.user.findFirst%28%29%60%20is%20usually%20caused%20by%20a%20mismatch%20between%20your%20Prisma%20schema%20and%20what%20Better%20Auth%20expects%2C%20or%20by%20database%20connectivity%20issues.%20For%20Better%20Auth%20to%20work%20with%20Prisma%2C%20your%20%60User%60%20model%20in%20%60schema.prisma%60%20should%20have%20specific%20fields%20and%20mappings%2C%20including%20%60id%60%2C%20%60name%60%2C%20%60email%60%2C%20%60emailVerified%60%20%28as%20a%20Boolean%29%2C%20and%20relations%20to%20%60Session%60%2C%20%60Account%60%2C%20and%20%60TwoFactor%60%20models%2C%20plus%20unique%20constraints%20and%20%60%40%40map%28%22user%22%29%60%20for%20table%20mapping.%20You%20can%20see%20the%20exact%20expected%20schema%20%5Bhere%5D%28https%3A//github.com/better-auth/better-auth/blob/c1656d0d70f845d1b380db94749bafb4c90596f8/packages/cli/test/__snapshots__/schema.prisma%23L11-L89%29.%0A%0ACommon%20causes%20for%20this%20error%3A%0A-%20The%20Prisma%20User%20model%20is%20missing%20required%20fields%20or%20has%20incorrect%20types%20%28e.g.%2C%20%60emailVerified%60%20as%20%60DateTime%3F%60%20instead%20of%20%60Boolean%60%29%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/3469%29.%0A-%20The%20User%20model/table%20name%20or%20mapping%20%28%60%40%40map%60%29%20does%20not%20match%20what%20Better%20Auth%20expects.%0A-%20There%20is%20a%20%60password%60%20field%20in%20the%20User%20model%2C%20which%20should%20be%20removed%E2%80%94Better%20Auth%20handles%20passwords%20via%20the%20Account%20model%27s%20%60credentials%60%20property%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/discussions/6100%29.%0A-%20The%20database%20schema%20and%20Prisma%20client%20are%20out%20of%20sync%20%28run%20%60prisma%20migrate%60%20and%20%60prisma%20generate%60%20after%20any%20changes%29.%0A-%20Prisma%20strictUndefinedChecks%20is%20enabled%20and%20undefined%20values%20are%20not%20filtered%20out%20in%20plugin-added%20fields%3B%20you%20may%20need%20to%20use%20a%20workaround%20with%20%60Prisma.skip%60%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/4341%23issuecomment-3241435692%29.%0A-%20The%20database%20is%20not%20running%20or%20accessible%20from%20your%20backend.%0A%0AFor%20NestJS%2C%20make%20sure%20global%20body%20parsing%20is%20disabled%20for%20Better%20Auth%20routes%20and%20use%20custom%20middleware%20if%20needed%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/171%29.%0A%0AIf%20you%20share%20your%20current%20%60schema.prisma%60%20User%2C%20Account%2C%20Session%2C%20and%20related%20models%2C%20I%20can%20help%20spot%20any%20mismatches.%20Otherwise%2C%20check%20your%20schema%20against%20the%20%5Breference%5D%28https%3A//github.com/better-auth/better-auth/blob/c1656d0d70f845d1b380db94749bafb4c90596f8/packages/cli/test/__snapshots__/schema.prisma%23L11-L89%29%2C%20remove%20any%20%60password%60%20fields%2C%20and%20ensure%20you%20run%20migrations%20and%20generate%20the%20Prisma%20client%20after%20changes.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6728)
Author
Owner

@Paola3stefania commented on GitHub (Jan 11, 2026):

HI @Arutowk is still an issue with last version?

<!-- gh-comment-id:3733727735 --> @Paola3stefania commented on GitHub (Jan 11, 2026): HI @Arutowk is still an issue with last version?
Author
Owner

@Paola3stefania commented on GitHub (Jan 11, 2026):

Hey @Arutowk

Looking at your config and the error, I think I can help! The issue is that your auth.ts is missing the database configuration. The ECONNREFUSED error happens because Better Auth doesn't know how to connect to your db

your current config:

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

should include the Prisma adapter like this:

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

const prisma = new PrismaClient();

export const auth = betterAuth({
  database: prismaAdapter(prisma, {
    provider: "postgresql", // since you're using pg
  }),
  emailAndPassword: {  
    enabled: true
  },
  // ...rest of your config
});

Also, a couple things to double-check:

  1. Make sure PostgreSQL is running on your machine
  2. Verify your DATABASE_URL in .env is correct and the database exists
  3. Test Prisma can connect by running npx prisma db push

Once the database config is added and Prisma can connect, run the Better Auth CLI to generate the required schema:

npx @better-auth/cli generate

Then apply it with npx prisma db push

Let me know if that helps :)

<!-- gh-comment-id:3733741369 --> @Paola3stefania commented on GitHub (Jan 11, 2026): Hey @Arutowk Looking at your config and the error, I think I can help! The issue is that your `auth.ts` is missing the **database configuration**. The `ECONNREFUSED` error happens because Better Auth doesn't know how to connect to your db your current config: ```ts import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` should include the Prisma adapter like this: ```ts import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import { PrismaClient } from "@prisma/client"; const prisma = new PrismaClient(); export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql", // since you're using pg }), emailAndPassword: { enabled: true }, // ...rest of your config }); ``` Also, a couple things to double-check: 1. **Make sure PostgreSQL is running** on your machine 2. **Verify your `DATABASE_URL`** in `.env` is correct and the database exists 3. **Test Prisma can connect** by running `npx prisma db push` Once the database config is added and Prisma can connect, run the Better Auth CLI to generate the required schema: ```bash npx @better-auth/cli generate ``` Then apply it with `npx prisma db push` Let me know if that helps :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19234