{"id":16732,"library":"nestjs-better-auth-fastify","title":"NestJS Better Auth Fastify Module","description":"The `nestjs-better-auth-fastify` package provides a dedicated NestJS module for integrating authentication capabilities specifically when using the Fastify platform adapter. It acts as a bridge, leveraging the underlying `better-auth` library to deliver authentication services tailored for high-performance Fastify-based NestJS applications. Currently, the package is in early development, reflected by its 0.0.24 version, which implies that API surfaces may change without adhering to strict semantic versioning, although recent releases show largely minor updates. Its core differentiator lies in its optimized integration with Fastify, providing a specialized solution for developers prioritizing Fastify's performance benefits within the NestJS ecosystem, rather than a generic authentication module. While recent changes have been minimal, early versions typically address fundamental architectural considerations and bug fixes, such as making `@nestjs/graphql` an optional dependency.","status":"active","version":"0.0.24","language":"javascript","source_language":"en","source_url":"https://github.com/roisuladib/nestjs-better-auth-fastify","tags":["javascript","nestjs","better-auth","auth","nestjs-better-auth","nestjs-better-auth-fastify","typescript"],"install":[{"cmd":"npm install nestjs-better-auth-fastify","lang":"bash","label":"npm"},{"cmd":"yarn add nestjs-better-auth-fastify","lang":"bash","label":"yarn"},{"cmd":"pnpm add nestjs-better-auth-fastify","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core NestJS dependency for modules, controllers, etc.","package":"@nestjs/common","optional":false},{"reason":"Core NestJS dependency for application bootstrapping.","package":"@nestjs/core","optional":false},{"reason":"Required if using GraphQL features with the module, made optional in v0.0.17.","package":"@nestjs/graphql","optional":true},{"reason":"The module is specifically designed for the Fastify platform.","package":"@nestjs/platform-fastify","optional":false},{"reason":"The underlying authentication library providing the core logic.","package":"better-auth","optional":false},{"reason":"The web server framework that NestJS uses via the Fastify adapter.","package":"fastify","optional":false},{"reason":"Build-time dependency for type checking, required by peer deps.","package":"typescript","optional":true}],"imports":[{"note":"Main module for registration in NestJS root or feature modules. Primarily used with ESM imports in modern NestJS projects.","wrong":"const BetterAuthFastifyModule = require('nestjs-better-auth-fastify').BetterAuthFastifyModule;","symbol":"BetterAuthFastifyModule","correct":"import { BetterAuthFastifyModule } from 'nestjs-better-auth-fastify';"},{"note":"Guard to protect routes, typically applied with `@UseGuards(BetterAuthGuard)`.","symbol":"BetterAuthGuard","correct":"import { BetterAuthGuard } from 'nestjs-better-auth-fastify';"},{"note":"Interface or type definition for module configuration options. Used for type safety when configuring the module.","symbol":"BetterAuthConfig","correct":"import { BetterAuthConfig } from 'nestjs-better-auth-fastify';"}],"quickstart":{"code":"import { NestFactory } from '@nestjs/core';\nimport { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';\nimport { Module } from '@nestjs/common';\nimport { BetterAuthFastifyModule } from 'nestjs-better-auth-fastify';\n\n@Module({\n  imports: [\n    BetterAuthFastifyModule.forRoot({\n      secret: process.env.AUTH_SECRET ?? 'super-secret-jwt-key',\n      expiresIn: '1h',\n      // Other better-auth specific configurations would go here\n      // For example, strategy configuration:\n      // strategies: [\n      //   { name: 'jwt', handler: () => ({ /* JWT strategy setup */ }) }\n      // ]\n    }),\n  ],\n  controllers: [],\n  providers: [],\n})\nclass AppModule {}\n\nasync function bootstrap() {\n  const app = await NestFactory.create<NestFastifyApplication>(\n    AppModule,\n    new FastifyAdapter(),\n  );\n\n  app.listen(3000, () => {\n    console.log('NestJS application with Fastify and BetterAuth listening on port 3000');\n  });\n}\n\nbootstrap();","lang":"typescript","description":"This quickstart demonstrates setting up a basic NestJS application using Fastify as the platform adapter and integrating `nestjs-better-auth-fastify` with a minimal configuration."},"warnings":[{"fix":"Always pin to exact versions (e.g., `\"nestjs-better-auth-fastify\": \"0.0.24\"`) or use caret ranges with caution. Thoroughly test updates in development environments.","message":"As a package in the 0.0.x version range, any release may introduce breaking changes without adhering to strict semantic versioning (e.g., a minor release might contain breaking API changes). Always review the changelog before upgrading.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"Ensure you are using `v0.0.17` or newer if you wish to use the module without installing `@nestjs/graphql`. If on an older version and not using GraphQL, consider installing `@nestjs/graphql` as a temporary workaround or upgrade.","message":"Prior to v0.0.17, the `@nestjs/graphql` peer dependency was not truly optional, potentially causing installation or runtime issues if GraphQL was not used. This has since been fixed using dynamic imports.","severity":"gotcha","affected_versions":"<0.0.17"},{"fix":"Ensure your `main.ts` or `main.js` explicitly configures the NestJS application to use `new FastifyAdapter()` when calling `NestFactory.create()`.","message":"The module requires `@nestjs/platform-fastify` and `fastify` to be correctly installed and configured in your NestJS application. Using a different platform adapter (e.g., Express) will lead to runtime errors or incorrect behavior.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Verify `better-auth` is listed in your `package.json` and installed. Check the `forRoot` configuration for any missing required properties or incorrect types as per `better-auth`'s documentation.","cause":"The `better-auth` library (or its dependencies) is not properly installed or accessible, or the configuration passed to `forRoot` is malformed.","error":"Error: Nest can't resolve dependencies of the BetterAuthFastifyModule (?). Please make sure that the argument at index [0] is available in the RootTestModule context."},{"fix":"Ensure `NestFactory.create` is explicitly typed and instantiated with `new FastifyAdapter()`. Example: `await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter());`","cause":"Attempting to use Fastify-specific application methods (like `listen` on `NestFastifyApplication`) on a generic `INestApplication` instance, likely because the `FastifyAdapter` was not correctly passed during `NestFactory.create`.","error":"TypeError: app.listen is not a function"}],"ecosystem":"npm"}