Skip to main content

NestJS + better-auth

04 Aug 2026
nest.jsbetter-authbackend

During these days, I’ve been experimenting with integrating Better Auth into a NestJS application, and I was surprised by how clean the setup can be compared to building an authentication system from scratch.

What I Set Up

The integration includes:

  • NestJS + Better Auth
  • @thallesp/nestjs-better-auth
  • Prisma ORM
  • PostgreSQL
  • Global Better Auth configuration through NestJS modules
  • Custom user fields
  • Token-based access control
  • Login tracking and password reset fields

Why I Like Better Auth

One thing I really like about Better Auth is that it provides a complete authentication foundation without making the system difficult to customize.

It gives you features such as:

  • Token-based access control
  • Two-factor authentication
  • Passkeys
  • Multi-session support
  • SSO / enterprise authentication features

This means I can spend more time building the actual application instead of repeatedly implementing authentication from scratch.

One Important NestJS Issue

While integrating Better Auth, I ran into an interesting issue with NestJS's default body parser.

NestJS uses Express and automatically applies body-parser.

For example, a request like:

{
  "email": "john@example.com",
  "password": "password123"
}

becomes:

req.body = {
  email: "john@example.com",
  password: "password123",
};

Normally, this is exactly what we want.

However, Better Auth may need access to the original request payload for certain authentication features, including signature verification and other security-sensitive operations.

Because NestJS has already parsed the request body, Better Auth may no longer have access to the original raw request bytes.

The Solution

The solution is to configure NestJS so that the default global body parser doesn't interfere with Better Auth.

Better Auth can then register its own parser while keeping access to the original request body through:

rawBody: true

This allows the application to work with both:

  • The parsed request body
  • The original raw request payload

Overall, Better Auth has been a really interesting experience so far.

It provides a lot of authentication functionality out of the box while still giving developers enough flexibility to customize the system around their application's requirements.