{"_id":"@buiducnhat/nest-better-auth","_rev":"4-8bae853ba36ca24a9eeb550ae43c395f","name":"@buiducnhat/nest-better-auth","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@buiducnhat/nest-better-auth","version":"1.0.0","keywords":["nest","nestjs","better-auth","auth","nestjs-better-auth","express","fastify"],"author":{"url":"https://github.com/buiducnhat","name":"buiducnhat","email":"nhaths4701@gmail.com"},"license":"MIT","_id":"@buiducnhat/nest-better-auth@1.0.0","maintainers":[{"name":"buiducnhat","email":"nhaths4701@gmail.com"}],"homepage":"https://github.com/buiducnhat/nest-better-auth#readme","bugs":{"url":"https://github.com/buiducnhat/nest-better-auth/issues"},"dist":{"shasum":"cf61cd04ff06c5b0bf06c5d48076bd170a01a9c2","tarball":"https://registry.npmjs.org/@buiducnhat/nest-better-auth/-/nest-better-auth-1.0.0.tgz","fileCount":9,"integrity":"sha512-4wiYrsPMh97sXrCvdMojCzbqSviYSUrg3QnkQpHW3p92FeBezaNdg7Fiwi0feV9x0BBN3E0OwObIkFnzMOZ/Tw==","signatures":[{"sig":"MEUCID+889DPnSsUxfRTOsuEj/tj9ALXzrhd/z7hTQxtnmfoAiEAoaXFtQPSv5xCqheUor/x8YfMQcTNFVfS54xSLLEd3oc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@buiducnhat%2fnest-better-auth@1.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":5382959},"main":"dist/index.js","_from":"file:buiducnhat-nest-better-auth-1.0.0.tgz","types":"dist/index.d.ts","module":"dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"}},"scripts":{"lint":"eslint . --ext .ts,.js,.tsx,.jsx","build":"rimraf dist && tsup src/index.ts --dts --format esm,cjs --sourcemap --clean","format":"prettier --write \"src/**/*.{ts,js,json,md}\"","prebuild":"rimraf dist"},"_npmUser":{"name":"buiducnhat","email":"nhaths4701@gmail.com"},"_resolved":"/tmp/7f407a4e838ff044706908857897aaf0/buiducnhat-nest-better-auth-1.0.0.tgz","_integrity":"sha512-4wiYrsPMh97sXrCvdMojCzbqSviYSUrg3QnkQpHW3p92FeBezaNdg7Fiwi0feV9x0BBN3E0OwObIkFnzMOZ/Tw==","repository":{"url":"git+https://github.com/buiducnhat/nest-better-auth.git","type":"git"},"_npmVersion":"10.8.2","description":"NestJs Better Auth package, work with express and fastify","directories":{},"_nodeVersion":"20.19.4","_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.20.4","jest":"^30.0.0","tsup":"^8.5.0","eslint":"^9.18.0","rimraf":"^6.0.1","express":"^5.1.0","fastify":"^5.5.0","globals":"^16.0.0","prettier":"^3.4.2","@eslint/js":"^9.18.0","typescript":"^5.7.3","better-auth":"^1.3.6","@nestjs/core":"^11.1.6","@nestjs/common":"^11.1.6","@nestjs/config":"^4.0.2","@types/express":"^5.0.3","tsconfig-paths":"^4.2.0","@eslint/eslintrc":"^3.2.0","typescript-eslint":"^8.20.0","eslint-config-prettier":"^10.0.1","eslint-plugin-prettier":"^5.2.2","@nestjs/platform-express":"^11.1.6","@nestjs/platform-fastify":"^11.1.6","@trivago/prettier-plugin-sort-imports":"^5.2.2"},"peerDependencies":{"better-auth":"^1.3.6","@nestjs/core":"^11.1.6","@nestjs/common":"^11.1.6"},"_npmOperationalInternal":{"tmp":"tmp/nest-better-auth_1.0.0_1755402073479_0.26717297232468407","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@buiducnhat/nest-better-auth","version":"1.0.1","keywords":["nest","nestjs","better-auth","auth","nestjs-better-auth","express","fastify"],"author":{"url":"https://github.com/buiducnhat","name":"buiducnhat","email":"nhaths4701@gmail.com"},"license":"MIT","_id":"@buiducnhat/nest-better-auth@1.0.1","maintainers":[{"name":"buiducnhat","email":"nhaths4701@gmail.com"}],"homepage":"https://github.com/buiducnhat/nest-better-auth#readme","bugs":{"url":"https://github.com/buiducnhat/nest-better-auth/issues"},"dist":{"shasum":"dea9c56f594ae469b4496be7d721a934242c69fc","tarball":"https://registry.npmjs.org/@buiducnhat/nest-better-auth/-/nest-better-auth-1.0.1.tgz","fileCount":9,"integrity":"sha512-Ep1527N6dQS0bEt0Y1s4sjKguVcPI+o4emml1nuev1iqZBs9Zm81HqjmYNqZUeLs3uXzF7zbcH7e2heQRvkEWg==","signatures":[{"sig":"MEYCIQDL3pggpyp5879VFth5JMGPy2D4SumhWYv8CAahsrYHJwIhAPAKZAhRlbv+gmtzIhChnxIMzc+ol1eDgTFbcuIsfzDV","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@buiducnhat%2fnest-better-auth@1.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":5384234},"main":"dist/index.js","_from":"file:buiducnhat-nest-better-auth-1.0.1.tgz","types":"dist/index.d.ts","module":"dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"}},"scripts":{"lint":"eslint . --ext .ts,.js,.tsx,.jsx","build":"rimraf dist && tsup src/index.ts --dts --format esm,cjs --sourcemap --clean","format":"prettier --write \"src/**/*.{ts,js,json,md}\"","prebuild":"rimraf dist"},"_npmUser":{"name":"buiducnhat","email":"nhaths4701@gmail.com"},"_resolved":"/tmp/4084305d38d8010459ab4f49552b551d/buiducnhat-nest-better-auth-1.0.1.tgz","_integrity":"sha512-Ep1527N6dQS0bEt0Y1s4sjKguVcPI+o4emml1nuev1iqZBs9Zm81HqjmYNqZUeLs3uXzF7zbcH7e2heQRvkEWg==","repository":{"url":"git+https://github.com/buiducnhat/nest-better-auth.git","type":"git"},"_npmVersion":"10.8.2","description":"NestJs Better Auth package, work with express and fastify","directories":{},"_nodeVersion":"20.19.4","_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.20.4","jest":"^30.0.0","tsup":"^8.5.0","eslint":"^9.18.0","rimraf":"^6.0.1","express":"^5.1.0","fastify":"^5.5.0","globals":"^16.0.0","prettier":"^3.4.2","@eslint/js":"^9.18.0","typescript":"^5.7.3","better-auth":"^1.3.6","@nestjs/core":"^11.1.6","@nestjs/common":"^11.1.6","@nestjs/config":"^4.0.2","@types/express":"^5.0.3","tsconfig-paths":"^4.2.0","@eslint/eslintrc":"^3.2.0","typescript-eslint":"^8.20.0","eslint-config-prettier":"^10.0.1","eslint-plugin-prettier":"^5.2.2","@nestjs/platform-express":"^11.1.6","@nestjs/platform-fastify":"^11.1.6","@trivago/prettier-plugin-sort-imports":"^5.2.2"},"peerDependencies":{"better-auth":"^1.3.6","@nestjs/core":"^11.1.6","@nestjs/common":"^11.1.6"},"_npmOperationalInternal":{"tmp":"tmp/nest-better-auth_1.0.1_1755483757094_0.4459308380465383","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@buiducnhat/nest-better-auth","version":"1.0.2","keywords":["nest","nestjs","better-auth","auth","nestjs-better-auth","express","fastify"],"author":{"url":"https://github.com/buiducnhat","name":"buiducnhat","email":"nhaths4701@gmail.com"},"license":"MIT","_id":"@buiducnhat/nest-better-auth@1.0.2","maintainers":[{"name":"buiducnhat","email":"nhaths4701@gmail.com"}],"homepage":"https://github.com/buiducnhat/nest-better-auth#readme","bugs":{"url":"https://github.com/buiducnhat/nest-better-auth/issues"},"dist":{"shasum":"618559fa0b31d6094a81252cd86432daf7fd1e1d","tarball":"https://registry.npmjs.org/@buiducnhat/nest-better-auth/-/nest-better-auth-1.0.2.tgz","fileCount":9,"integrity":"sha512-VPMja5805L/2bNbIO+q244BiniDpFcE706ijX3mcmMPOJO5FDd4U9+Dv3vNQ/J9qS0wDHvke9xSLK771uB7woA==","signatures":[{"sig":"MEQCIHduznWMxt4NcekUWKT1DXXOgDRlfo3FqimaIxYH+DulAiAMIo6IXkvI8sHFVsBn9AhkezbQeT2SNWADPuaBCV/VRQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@buiducnhat%2fnest-better-auth@1.0.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":5386244},"main":"dist/index.js","_from":"file:buiducnhat-nest-better-auth-1.0.2.tgz","types":"dist/index.d.ts","module":"dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"}},"scripts":{"lint":"eslint . --ext .ts,.js,.tsx,.jsx","build":"rimraf dist && tsup src/index.ts --dts --format esm,cjs --sourcemap --clean","format":"prettier --write \"src/**/*.{ts,js,json,md}\"","prebuild":"rimraf dist"},"_npmUser":{"name":"buiducnhat","email":"nhaths4701@gmail.com"},"_resolved":"/tmp/6308f94bbb33e95695953ebae399f5ea/buiducnhat-nest-better-auth-1.0.2.tgz","_integrity":"sha512-VPMja5805L/2bNbIO+q244BiniDpFcE706ijX3mcmMPOJO5FDd4U9+Dv3vNQ/J9qS0wDHvke9xSLK771uB7woA==","repository":{"url":"git+https://github.com/buiducnhat/nest-better-auth.git","type":"git"},"_npmVersion":"10.8.2","description":"NestJs Better Auth package, work with express and fastify","directories":{},"_nodeVersion":"20.19.4","_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.20.4","jest":"^30.0.0","tsup":"^8.5.0","eslint":"^9.18.0","rimraf":"^6.0.1","express":"^5.1.0","fastify":"^5.5.0","globals":"^16.0.0","prettier":"^3.4.2","@eslint/js":"^9.18.0","typescript":"^5.7.3","better-auth":"^1.3.6","@nestjs/core":"^11.1.6","@nestjs/common":"^11.1.6","@nestjs/config":"^4.0.2","@types/express":"^5.0.3","tsconfig-paths":"^4.2.0","@eslint/eslintrc":"^3.2.0","typescript-eslint":"^8.20.0","eslint-config-prettier":"^10.0.1","eslint-plugin-prettier":"^5.2.2","@nestjs/platform-express":"^11.1.6","@nestjs/platform-fastify":"^11.1.6","@trivago/prettier-plugin-sort-imports":"^5.2.2"},"peerDependencies":{"better-auth":"^1.3.6","@nestjs/core":"^11.1.6","@nestjs/common":"^11.1.6"},"_npmOperationalInternal":{"tmp":"tmp/nest-better-auth_1.0.2_1755561559619_0.4969765821751315","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@buiducnhat/nest-better-auth","version":"1.1.0","description":"NestJs Better Auth package, work with express and fastify","keywords":["nest","nestjs","better-auth","auth","nestjs-better-auth","express","fastify"],"author":{"name":"buiducnhat","email":"nhaths4701@gmail.com","url":"https://github.com/buiducnhat"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/buiducnhat/nest-better-auth.git"},"bugs":{"url":"https://github.com/buiducnhat/nest-better-auth/issues"},"homepage":"https://github.com/buiducnhat/nest-better-auth#readme","main":"dist/index.js","module":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"}},"peerDependencies":{"@nestjs/common":"^11.1.6","@nestjs/core":"^11.1.6","better-auth":"^1.3.6"},"devDependencies":{"@eslint/eslintrc":"^3.2.0","@eslint/js":"^9.18.0","@nestjs/common":"^11.1.6","@nestjs/config":"^4.0.2","@nestjs/core":"^11.1.6","@nestjs/platform-express":"^11.1.6","@nestjs/platform-fastify":"^11.1.6","@trivago/prettier-plugin-sort-imports":"^5.2.2","@types/express":"^5.0.3","better-auth":"^1.3.6","eslint":"^9.18.0","eslint-config-prettier":"^10.0.1","eslint-plugin-prettier":"^5.2.2","express":"^5.1.0","fastify":"^5.5.0","globals":"^16.0.0","jest":"^30.0.0","prettier":"^3.4.2","rimraf":"^6.0.1","tsconfig-paths":"^4.2.0","tsup":"^8.5.0","tsx":"^4.20.4","typescript":"^5.7.3","typescript-eslint":"^8.20.0"},"scripts":{"prebuild":"rimraf dist","build":"rimraf dist && tsup src/index.ts --dts --format esm,cjs --sourcemap --clean","lint":"eslint . --ext .ts,.js,.tsx,.jsx","format":"prettier --write \"src/**/*.{ts,js,json,md}\""},"_id":"@buiducnhat/nest-better-auth@1.1.0","_integrity":"sha512-I9AGsSBlfdF5B/cmFrkOKeU4zGXSqdWa0eattVydzNEvm0r5NKmD7ZXjhFCux4YFMz895apTGRO8Gk/USN0DDw==","_resolved":"/tmp/d68d4b8f747272b39b458f3fb5f75175/buiducnhat-nest-better-auth-1.1.0.tgz","_from":"file:buiducnhat-nest-better-auth-1.1.0.tgz","_nodeVersion":"20.19.4","_npmVersion":"10.8.2","dist":{"integrity":"sha512-I9AGsSBlfdF5B/cmFrkOKeU4zGXSqdWa0eattVydzNEvm0r5NKmD7ZXjhFCux4YFMz895apTGRO8Gk/USN0DDw==","shasum":"c307e175b426f43770c4d0fcb55c808879fe4937","tarball":"https://registry.npmjs.org/@buiducnhat/nest-better-auth/-/nest-better-auth-1.1.0.tgz","fileCount":9,"unpackedSize":5386490,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@buiducnhat%2fnest-better-auth@1.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDsR8YeJ4KANZT1RW6ubhBYzUKZGkGKeDOSKmI9uL3CIgIhALa7gwoQ246FHSbbdcEbRC1+vGtfhNWLpYUkA5NFd1RG"}]},"_npmUser":{"name":"buiducnhat","email":"nhaths4701@gmail.com"},"directories":{},"maintainers":[{"name":"buiducnhat","email":"nhaths4701@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/nest-better-auth_1.1.0_1755571326506_0.11309141084500962"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-17T03:41:13.312Z","modified":"2025-08-19T02:42:07.187Z","1.0.0":"2025-08-17T03:41:13.729Z","1.0.1":"2025-08-18T02:22:37.325Z","1.0.2":"2025-08-18T23:59:19.868Z","1.1.0":"2025-08-19T02:42:06.818Z"},"bugs":{"url":"https://github.com/buiducnhat/nest-better-auth/issues"},"author":{"name":"buiducnhat","email":"nhaths4701@gmail.com","url":"https://github.com/buiducnhat"},"license":"MIT","homepage":"https://github.com/buiducnhat/nest-better-auth#readme","keywords":["nest","nestjs","better-auth","auth","nestjs-better-auth","express","fastify"],"repository":{"type":"git","url":"git+https://github.com/buiducnhat/nest-better-auth.git"},"description":"NestJs Better Auth package, work with express and fastify","maintainers":[{"name":"buiducnhat","email":"nhaths4701@gmail.com"}],"readme":"# nest-better-auth\n\nA NestJS integration library for [better-auth](https://www.better-auth.com/), providing seamless authentication support for both Express and Fastify platforms.\n\n[![npm version](https://badge.fury.io/js/%40buiducnhat%2Fnest-better-auth.svg)](https://badge.fury.io/js/%40buiducnhat%2Fnest-better-auth)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Features\n\n- 🚀 **Easy Integration**: Simple setup with NestJS modules\n- 🔒 **Authentication Guard**: Built-in guard for protecting routes\n- 🎯 **Decorators**: Convenient decorators for accessing user session and data, and isPublic for marking routes as publicly accessible\n- 🌐 **Multi-Platform**: Supports both Express and Fastify\n- ⚙️ **Flexible Configuration**: Both synchronous and asynchronous configuration options\n- 📝 **Type-Safe**: Full TypeScript support with proper typing\n\n## Installation\n\nBefore you start, make sure you have a Better Auth instance configured. If you haven't done that yet, check out the [installation](https://www.better-auth.com/docs/installation).\n\n> [!WARNING]\n> This is not the official library of Better Auth. It is a community-driven library that is not officially supported by Better Auth.\n\n```bash\nnpm install @buiducnhat/nest-better-auth\n# or\nyarn add @buiducnhat/nest-better-auth\n# or\npnpm add @buiducnhat/nest-better-auth\n```\n\n## Quick Start\n\n### 1. Basic Setup with Express\n\n```typescript\nimport { AuthGuard, AuthModule } from \"@buiducnhat/nest-better-auth\";\nimport { Module } from \"@nestjs/common\";\nimport { APP_GUARD } from \"@nestjs/core\";\nimport { betterAuth } from \"better-auth\";\n\n@Module({\n  imports: [\n    AuthModule.forRoot({\n      betterAuth: betterAuth({\n        basePath: \"/auth\",\n        secret: process.env.AUTH_SECRET,\n        emailAndPassword: {\n          enabled: true,\n        },\n        database: {\n          // Your database configuration\n        },\n      }),\n      options: {\n        routingProvider: \"express\", // default\n        jsonParser: true, // default\n      },\n    }),\n  ],\n  providers: [\n    {\n      provide: APP_GUARD,\n      useClass: AuthGuard,\n    },\n  ],\n})\nexport class AppModule {}\n```\n\n> [!WARNING]\n> Due to [this document](https://www.better-auth.com/docs/integrations/express#mount-the-handler):\n>\n> Don’t use express.json() before the Better Auth handler. Use it only for other routes, or the client API will get stuck on \"pending\".\n>\n> So, you need to turn off the `bodyParser` option on `main.ts` file.\n\n```typescript\nasync function bootstrap() {\n  const app = await NestFactory.create(AppModule, { bufferLogs: true, bodyParser: false });\n  await app.listen(9001);\n}\n```\n\n### 2. Basic Setup with Fastify\n\n```typescript\nimport { AuthGuard, AuthModule } from \"@buiducnhat/nest-better-auth\";\nimport { Module } from \"@nestjs/common\";\nimport { APP_GUARD } from \"@nestjs/core\";\nimport { betterAuth } from \"better-auth\";\n\n@Module({\n  imports: [\n    AuthModule.forRoot({\n      betterAuth: betterAuth({\n        basePath: \"/auth\",\n        secret: process.env.AUTH_SECRET,\n        emailAndPassword: {\n          enabled: true,\n        },\n        database: {\n          // Your database configuration\n        },\n      }),\n      options: {\n        routingProvider: \"fastify\",\n      },\n    }),\n  ],\n  providers: [\n    {\n      provide: APP_GUARD,\n      useClass: AuthGuard,\n    },\n  ],\n})\nexport class AppModule {}\n```\n\n### 3. Using Controllers with Authentication\n\n```typescript\nimport { CurrentUser, IsPublic, Session, User, UserSession } from \"@buiducnhat/nest-better-auth\";\nimport { Body, Controller, Get, Post } from \"@nestjs/common\";\n\n@Controller()\nexport class AppController {\n  // Public route - no authentication required\n  @IsPublic()\n  @Get(\"public\")\n  getPublicData() {\n    return { message: \"This is a public endpoint\" };\n  }\n\n  // Protected route - authentication required\n  @Get(\"protected\")\n  getProtectedData() {\n    return { message: \"This is a protected endpoint\" };\n  }\n\n  // Get current user information\n  @Get(\"me\")\n  getCurrentUser(@CurrentUser() user: User) {\n    return user;\n  }\n\n  // Get full session information\n  @Get(\"session\")\n  getSession(@Session() session: UserSession) {\n    return session;\n  }\n\n  // Protected POST route\n  @Post(\"user-action\")\n  performUserAction(@CurrentUser() user: User, @Body() data: any) {\n    return {\n      user: user.id,\n      action: \"performed\",\n      data,\n    };\n  }\n}\n```\n\n## Advanced Configuration\n\n### Async Configuration\n\nFor more complex setups, you can use async configuration with dependency injection:\n\n```typescript\nimport { AuthGuard, AuthModule } from \"@buiducnhat/nest-better-auth\";\nimport { Module } from \"@nestjs/common\";\nimport { ConfigModule, ConfigService } from \"@nestjs/config\";\nimport { APP_GUARD } from \"@nestjs/core\";\nimport { betterAuth } from \"better-auth\";\n\n@Module({\n  imports: [\n    ConfigModule.forRoot(),\n    AuthModule.forRootAsync({\n      imports: [ConfigModule],\n      inject: [ConfigService],\n      useFactory: (configService: ConfigService) => ({\n        betterAuth: betterAuth({\n          basePath: configService.get(\"AUTH_BASE_PATH\", \"/auth\"),\n          secret: configService.get(\"AUTH_SECRET\"),\n          emailAndPassword: {\n            enabled: true,\n          },\n          database: {\n            provider: configService.get(\"DB_PROVIDER\"),\n            url: configService.get(\"DATABASE_URL\"),\n          },\n        }),\n        options: {\n          routingProvider: configService.get(\"ROUTING_PROVIDER\", \"express\"),\n        },\n      }),\n    }),\n  ],\n  providers: [\n    {\n      provide: APP_GUARD,\n      useClass: AuthGuard,\n    },\n  ],\n})\nexport class AppModule {}\n```\n\n#### Configuration File Example\n\n```typescript\n// config/configuration.ts\nexport default () => ({\n  betterAuth: {\n    basePath: process.env.AUTH_BASE_PATH || \"/auth\",\n    secret: process.env.AUTH_SECRET,\n    database: {\n      provider: process.env.DB_PROVIDER || \"sqlite\",\n      url: process.env.DATABASE_URL || \"./database.db\",\n    },\n  },\n});\n```\n\n### Use the better-auth instance\n\nYou can use the better-auth instance to access the Better Auth API:\n\n```typescript\nimport { auth } from \"@/libs/auth\";\n// Use can create a dedicated auth.ts like better-auth traditional way for using cli, and infer its type for fully support API\nimport {\n  AuthGuard,\n  BETTER_AUTH_INSTANCE_TOKEN,\n  Session,\n  type UserSession,\n} from \"@buiducnhat/nest-better-auth\";\nimport { Controller, Get, Inject, Req, UseGuards } from \"@nestjs/common\";\nimport { ApiBearerAuth, ApiTags } from \"@nestjs/swagger\";\nimport { fromNodeHeaders } from \"better-auth/node\";\nimport type { Request } from \"express\";\n\n@ApiTags(\"Admin Users\")\n@ApiBearerAuth()\n@Controller(\"admin/users\")\n@UseGuards(AuthGuard)\nexport class AdminUsersController {\n  constructor(@Inject(BETTER_AUTH_INSTANCE_TOKEN) private readonly authInstance: typeof auth) {}\n  // You can absolutely use the Auth type from better-auth\n  // import { Auth } from \"better-auth\";\n  // ...\n  // constructor(@Inject(BETTER_AUTH_INSTANCE_TOKEN) private readonly authInstance: Auth) {}\n\n  @Get(\"/\")\n  getUsers(@Session() session: UserSession, @Req() req: Request) {\n    return this.authInstance.api.listUserAccounts({\n      headers: fromNodeHeaders(req.headers),\n    });\n  }\n}\n```\n\n## API Reference\n\n### AuthModule\n\n#### Static Methods\n\n- `forRoot(options)`: Configure the module synchronously\n- `forRootAsync(options)`: Configure the module asynchronously\n\n#### Options\n\n```typescript\ninterface AuthModuleOptions {\n  betterAuth: ReturnType<typeof betterAuth>;\n  options?: {\n    routingProvider?: \"express\" | \"fastify\"; // default: 'express'\n    jsonParser?: boolean; // default: true\n  };\n}\n```\n\n### AuthGuard\n\nA guard that protects routes by checking for valid authentication sessions.\n\n```typescript\nimport { AuthGuard } from '@buiducnhat/nest-better-auth';\nimport { APP_GUARD } from '@nestjs/core';\n\n// Apply globally\n{\n  provide: APP_GUARD,\n  useClass: AuthGuard,\n}\n\n// Apply to specific controllers\n@UseGuards(AuthGuard)\n@Controller('protected')\nexport class ProtectedController {}\n```\n\n### Decorators\n\n#### @IsPublic()\n\nMark routes as publicly accessible, bypassing the AuthGuard:\n\n```typescript\n@IsPublic()\n@Get('public')\ngetPublicData() {\n  return { message: 'No authentication required' };\n}\n```\n\n#### @CurrentUser()\n\nInject the current authenticated user:\n\n```typescript\n@Get('profile')\ngetProfile(@CurrentUser() user: User) {\n  return user;\n}\n```\n\n#### @Session()\n\nInject the full session object:\n\n```typescript\n@Get('session-info')\ngetSessionInfo(@Session() session: UserSession) {\n  return {\n    user: session.user,\n    sessionId: session.id,\n    expiresAt: session.expiresAt,\n  };\n}\n```\n\n## Error Handling\n\nThe library automatically handles authentication errors and returns appropriate HTTP status codes:\n\n- `401 Unauthorized`: When authentication is required but not provided\n- The library integrates with better-auth's error handling system\n\n```typescript\nimport { ArgumentsHost, Catch, ExceptionFilter } from \"@nestjs/common\";\nimport { APIError } from \"better-auth/api\";\n\n@Catch(APIError)\nexport class AuthExceptionFilter implements ExceptionFilter {\n  catch(exception: APIError, host: ArgumentsHost) {\n    const ctx = host.switchToHttp();\n    const response = ctx.getResponse();\n\n    response.status(exception.status).json({\n      statusCode: exception.status,\n      message: exception.message,\n      error: exception.body?.code,\n    });\n  }\n}\n```\n\n## Examples\n\nThe repository includes complete examples for different setups:\n\n- [Express Example](./example/with-express/) - Basic Express setup\n- [Fastify Example](./example/with-fastify/) - Basic Fastify setup\n- [Async Configuration Example](./example/with-for-root-async/) - Advanced async configuration\n\n## Integration with Better Auth\n\nThis library is designed to work seamlessly with better-auth features:\n\n### Plugins\n\n```typescript\nimport { bearer, twoFactor } from \"better-auth/plugins\";\n\nAuthModule.forRoot({\n  betterAuth: betterAuth({\n    plugins: [\n      bearer(), // Bearer token authentication\n      twoFactor(), // Two-factor authentication\n      // ... other plugins\n    ],\n  }),\n});\n```\n\n### Custom Authentication Logic\n\nYou can extend the AuthGuard for custom authentication logic:\n\n```typescript\nimport { AuthGuard } from \"@buiducnhat/nest-better-auth\";\nimport { Injectable } from \"@nestjs/common\";\n\n@Injectable()\nexport class CustomAuthGuard extends AuthGuard {\n  async canActivate(context: ExecutionContext): Promise<boolean> {\n    const isAuthenticated = await super.canActivate(context);\n\n    if (!isAuthenticated) return false;\n\n    // Add custom logic here\n    const request = context.switchToHttp().getRequest();\n    const user = request.user;\n\n    // Example: Check user role\n    if (user.role !== \"admin\") {\n      throw new ForbiddenException(\"Admin access required\");\n    }\n\n    return true;\n  }\n}\n```\n\n## Requirements\n\n- Node.js 18+\n- NestJS 10+\n- Better Auth 1.3.6+\n\n## Peer Dependencies\n\n- `@nestjs/common` ^11.1.6\n- `@nestjs/core` ^11.1.6\n- `better-auth` ^1.3.6\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Support\n\nIf you found this library helpful, please consider giving it a ⭐ on [GitHub](https://github.com/buiducnhat/nest-better-auth)!\n\nFor issues and feature requests, please use the [GitHub Issues](https://github.com/buiducnhat/nest-better-auth/issues).\n","readmeFilename":"README.md"}