NestJS Integration
This guide will show you how to integrate Better Auth with NestJS.
Before you start, make sure you have a Better Auth instance configured. If you haven't done that yet, check out the installation.
The NestJS integration is community maintained. If you encounter any issues, please open them at nestjs-better-auth.
Installation
Install the NestJS integration library:
Basic Setup
Currently, Better Auth's NestJS integration only supports Express and does not work with Fastify.
1. Disable Body Parser
Disable NestJS's built-in body parser to allow Better Auth to handle the raw request body:
2. Import AuthModule
Import the AuthModule
in your root module:
3. Protect Routes
Use the AuthGuard
to protect your routes:
Full Documentation
For comprehensive documentation including decorators, hooks, global guards, and advanced configuration, visit the NestJS Better Auth repository.