{"id":28202309,"url":"https://github.com/underfisk/nestjs-better-auth","last_synced_at":"2026-04-27T08:32:15.909Z","repository":{"id":292939392,"uuid":"982440193","full_name":"underfisk/nestjs-better-auth","owner":"underfisk","description":"A nestjs module to integrate better-auth","archived":false,"fork":false,"pushed_at":"2026-03-17T20:12:11.000Z","size":593,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-18T09:10:43.983Z","etag":null,"topics":["authentication","authorization","better-auth","jwt","nestjs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/underfisk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-05-12T22:21:22.000Z","updated_at":"2026-03-17T20:10:58.000Z","dependencies_parsed_at":"2025-05-12T23:28:49.466Z","dependency_job_id":"babe70f8-f13f-4a14-9896-32f68022d2cb","html_url":"https://github.com/underfisk/nestjs-better-auth","commit_stats":null,"previous_names":["underfisk/nestjs-better-auth"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/underfisk/nestjs-better-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/underfisk%2Fnestjs-better-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/underfisk%2Fnestjs-better-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/underfisk%2Fnestjs-better-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/underfisk%2Fnestjs-better-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/underfisk","download_url":"https://codeload.github.com/underfisk/nestjs-better-auth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/underfisk%2Fnestjs-better-auth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32329463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","authorization","better-auth","jwt","nestjs"],"created_at":"2025-05-17T00:12:40.181Z","updated_at":"2026-04-27T08:32:15.883Z","avatar_url":"https://github.com/underfisk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nestjs Better Auth Module\n\nA [better-auth](https://www.better-auth.com/) Nestjs module that supports Fastify and Express v5 http-adapters out of the box.\n\n### Getting Started\n\n#### Installing the library\n\n```sh\npnpm i nestjs-better-auth\n```\n\n### HTTP Adapters Support\n\nThis module supports two HTTP adapters out of the box:\n\n- **Express v5**\n\n  - [Better Auth Integration guide for Express](https://www.better-auth.com/docs/integrations/express)\n  - Default adapter for NestJS applications\n\n- **Fastify**\n  - [Better Auth Integration guide for Fastify](https://www.better-auth.com/docs/integrations/fastify)\n  - Higher performance alternative\n\nPlease refer to the respective integration guides for detailed setup instructions.\n\n### GraphQL Support\n\nThis library supports GraphQL context out of the box.\n\n#### Consuming `BetterAuthModule`\n\nSimply register the module in your `AppModule` (or your feature)\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { BetterAuthModule } from 'nestjs-better-auth';\n\n@Module({\n  imports: [\n    BetterAuthModule.forRoot({\n      betterAuthConfig: {\n        emailAndPassword: {\n          enabled: true,\n        },\n      },\n    }),\n  ],\n})\nclass AppModule {}\n```\n\nYou can also leverage `forRootAsync` if you need to inject any configuration/third-party value to build your config.\n\n#### Authentication Guard / Protecting your routes\n\nThis library exposes a `BetterAuthGuard` to protect authenticated routes. To use it globally for all routes, register it as follows:\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { BetterAuthModule, BetterAuthGuard } from 'nestjs-better-auth';\n\n@Module({\n  imports: [\n    BetterAuthModule.forRoot({\n      betterAuthConfig: {\n        emailAndPassword: {\n          enabled: true,\n        },\n        // ...your configuration\n      },\n    }),\n  ],\n  providers: [\n    {\n      provide: 'APP_GUARD',\n      useClass: BetterAuthGuard,\n    },\n  ],\n})\nclass AppModule {}\n```\n\nSome routes should be publicly accessible without session validation. You can provide a decorator token to the module to specify which routes should skip authentication.\nAlternatively, you can create your own Auth guard or apply the existing one manually to specific controllers or routes.\n\nExample:\n\n```typescript\nimport { Controller, Get, SetMetadata, Module } from '@nestjs/common';\n\nconst PublicRouteToken = Symbol('publicRoute');\nconst IsPublic = () =\u003e SetMetadata(PublicRouteToken, true);\n\n@Controller()\nclass MyController {\n  @IsPublic()\n  @Get()\n  publicRoute() {}\n\n  @Get()\n  authenticatedRoute() {}\n}\n\n@Module({\n  imports: [\n    BetterAuthModule.forRoot({\n      skipAuthDecoratorMetadataKey: PublicRouteToken,\n      betterAuthConfig: {\n        emailAndPassword: {\n          enabled: true,\n        },\n      },\n    }),\n  ],\n  providers: [\n    {\n      provide: 'APP_GUARD',\n      useClass: BetterAuthGuard,\n    },\n  ],\n})\nclass AppModule {}\n```\n\n### Why not full ESM?\n\nWe're maintaining **CommonJS** compatibility as many existing applications still use CJS. While we plan to transition to ESM in the future, this approach ensures broader compatibility for now.\n\n### HOOKS\n\nWIP\n\n### Read authenticated user\n\nYou can read the authenticated/current user session using `@CurrentUserSession` decorator.\nBy default, it will return the user and session but it accepts a parameter `user` or `session`, examples below\n\n```typescript\nimport { CurrentUserSession, BetterAuthUserSession } from 'nestjs-better-auth';\nimport { Controller } from '@nestjs/common';\n\nclass Controller {\n  @Get('me')\n  getMe(\n    @CurrentUserSession() userAndSession: BetterAuthUserSession,\n    @CurrentUserSession('user') user: BetterAuthUserSession['user'],\n    @CurrentUserSession('session') session: BetterAuthUserSession['session'],\n  ) {\n    // your logic\n  }\n}\n```\n\n### Contributing\n\nWe welcome contributions to improve nestjs-better-auth! Here's how you can help:\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\nPlease ensure you follow our coding standards and include appropriate tests for new features.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funderfisk%2Fnestjs-better-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funderfisk%2Fnestjs-better-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funderfisk%2Fnestjs-better-auth/lists"}