{"id":22913990,"url":"https://github.com/bpisano/nestjs-easy-auth","last_synced_at":"2026-04-20T06:07:21.166Z","repository":{"id":202815037,"uuid":"696178582","full_name":"bpisano/nestjs-easy-auth","owner":"bpisano","description":"Elegant and simple authentication solution for NestJS.","archived":false,"fork":false,"pushed_at":"2023-10-19T11:37:33.000Z","size":359,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-14T12:58:22.900Z","etag":null,"topics":["authentication","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bpisano.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2023-09-25T08:45:16.000Z","updated_at":"2023-10-21T19:04:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b68c2eb-6092-401a-ba8c-9ae7accd7eeb","html_url":"https://github.com/bpisano/nestjs-easy-auth","commit_stats":null,"previous_names":["bpisano/nestjs-easy-auth"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/bpisano/nestjs-easy-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bpisano%2Fnestjs-easy-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bpisano%2Fnestjs-easy-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bpisano%2Fnestjs-easy-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bpisano%2Fnestjs-easy-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bpisano","download_url":"https://codeload.github.com/bpisano/nestjs-easy-auth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bpisano%2Fnestjs-easy-auth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32035278,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"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","jwt","nestjs"],"created_at":"2024-12-14T05:12:46.898Z","updated_at":"2026-04-20T06:07:21.147Z","avatar_url":"https://github.com/bpisano.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NestJS Easy Auth\n\nElegant and simple authentication solution for NestJS.\n\n```typescript\n@Module({\n  imports: [\n    AuthModule.withConfiguration({\n      jwtConfig: {\n        secret: 'my-secret',\n        accessTokenExpiresIn: '1h',\n        refreshTokenExpiresIn: '1d',\n        tokenExtraction: ExtractJwt.fromAuthHeaderAsBearerToken(),\n        ignoreExpiration: false\n      },\n      modelProvider: DefaultModelProvider.withModels({\n        credentials: CredentialsMock,\n        user: UserMock\n      }),\n      methods: [SignInEmailPassword.forRoot(), LogInEmailPassword.forRoot()]\n    })\n  ]\n})\nexport class ApiModule {}\n```\n\n# Table of Contents\n\n- [Installation](#installation)\n- [Quick start](#quick-start)\n  1. [Provide your database](#1-provide-your-database)\n  2. [Provide your jwt configuration](#2-provide-your-jwt-configuration)\n  3. [Provide your models](#3-provide-your-models)\n  4. [Provide your authentication methods](#4-provide-your-authentication-methods)\n- [Documentation](#documentation)\n  - [Introduction](#introduction)\n  - [Authentication methods](#authentication-methods)\n    - [Sign in with email and password](#sign-in-with-email-and-password)\n    - [Login with email and password](#login-with-email-and-password)\n  - [Creating your own authentication method](#creating-your-own-authentication-method)\n\n# Installation\n\nYou can install the package using the following commands:\n\n```bash\n$ yarn\nyarn add nestjs-easy-auth\n\n$ npm\nnpm install nestjs-easy-auth\n```\n\n# Quick start\n\n### 1. Provide your database\n\nThis package allows you to use your own database for the credentials and user storage.\nYou can create your own `CredentialsStorage` and `UserStorage`.\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eUsing MongoDB\u003c/strong\u003e\u003c/summary\u003e\n\nYou can use MongoDB as the main storage. Thi, you can install [nestjs-easy-auth-mongo](https://github.com/bpisano/nestjs-easy-auth-mongo) which provides a MongoDB implementation.\nTo get started, import the `AuthMongoProviderModule` in your `ApiModule`.\n\n```bash\n$ yarn\nyarn add nestjs-easy-auth-mongo\n\n$ npm\nnpm install nestjs-easy-auth-mongo\n```\n\n```typescript\n@Module({\n  imports: [\n    AuthMongoProviderModule.withConfiguration({\n      dbName: 'your-database-name',\n      uri: 'mongodb://user:password@127.0.0.1:27017',\n      schemas: {\n        credentials: DBCredentialsSchema,\n        user: DBUserSchema\n      }\n    })\n  ]\n})\nexport class ApiModule {}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eUsing SQL\u003c/strong\u003e\u003c/summary\u003e\n    Comming soon...\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eUsing a custom database\u003c/strong\u003e\u003c/summary\u003e\n    See \u003ca href=\"## Providing a custom storage\"\u003eproviding a custom storage\u003c/a\u003e.\n\u003c/details\u003e\n\n### 2. Provide your jwt configuration\n\nProvide your jwt configuration using the `jwtConfig` property.\n\n```typescript\nAuthModule.withConfiguration({\n  jwtConfig: {\n    secret: 'my-secret',\n    accessTokenExpiresIn: '1h',\n    refreshTokenExpiresIn: '1d',\n    tokenExtraction: ExtractJwt.fromAuthHeaderAsBearerToken(),\n    ignoreExpiration: false\n  }\n});\n```\n\n### 3. Provide your models\n\nThis package allows you to use your own `Credentials` and `User` models.\nYour models needs to conforms to the `CredentialsRepresentation` and `UserRepresentation` interfaces.\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eCredentials model example\u003c/strong\u003e\u003c/summary\u003e\n\n```typescript\nexport class Credentials implements CredentialsRepresentation\u003cDBCredentials, PublicCredentials\u003e {\n  public constructor(\n    public readonly userId: string,\n    public readonly authType: string,\n    public readonly accessToken: string,\n    public readonly refreshToken: string,\n    public readonly accessTokenExpiration: Date,\n    public readonly refreshTokenExpiration: Date\n  ) {}\n\n  // Required to convert the model to a database model.\n  public toDatabaseModel(): DBCredentials {\n    return new DBCredentials(\n      this.userId,\n      this.authType,\n      this.accessToken,\n      this.refreshToken,\n      this.accessTokenExpiration,\n      this.refreshTokenExpiration\n    );\n  }\n\n  // Required to convert the model to a public model.\n  public toPublicModel(): PublicCredentials {\n    return new PublicCredentials(\n      this.userId,\n      this.authType,\n      this.accessToken,\n      this.refreshToken,\n      this.accessTokenExpiration,\n      this.refreshTokenExpiration\n    );\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eUser model example\u003c/strong\u003e\u003c/summary\u003e\n\n```typescript\nexport class User implements UserRepresentation\u003cDBUser, PublicUser\u003e {\n  public constructor(\n    public readonly id: string,\n    public readonly email: string,\n    public readonly hashedPassword?: string\n  ) {}\n\n  // Required to convert the model to a database model.\n  public toDatabaseModel(): DBUser {\n    return new DBUser(this.id, this.email, this.hashedPassword);\n  }\n\n  // Required to convert the model to a public model.\n  // Do not include the hashed password in the public model.\n  public toPublicModel(): PublicUser {\n    return new PublicUser(this.id, this.email);\n  }\n}\n```\n\n\u003c/details\u003e\n\nYou can provide your models using the `DefaultModelProvider` class.\n\n```typescript\nAuthModule.withConfiguration({\n  jwtConfig: { ... },\n  modelProvider: DefaultModelProvider.withModels({\n    credentials: CredentialsMock,\n    user: UserMock\n  })\n});\n```\n\n### 4. Provide your authentication methods\n\nYou can provide your authentication methods using the `methods` property.\nThese methods will be used to authenticate your users.\n\n```typescript\nAuthModule.withConfiguration({\n  jwtConfig: { ... },\n  modelProvider: DefaultModelProvider.withModels({ ... }),\n  methods: [SignInEmailPassword.forRoot(), LogInEmailPassword.forRoot()]\n});\n```\n\nWith theses methods, you can create and authentify users using their email and password with the following HTTP requests:\n\n```HTTP\nPOST /auth/sign-in\n{\n  \"email\": \"user@yourdomain.com\",\n  \"password\": \"my-password\"\n}\n```\n\n```HTTP\nPOST /auth/login\n{\n  \"email\": \"user@yourdomain.com\",\n  \"password\": \"my-password\"\n}\n```\n\nYou can also refresh you credentials using the `POST /auth/refresh` endpoint.\n\n```HTTP\nPOST /auth/refresh\n{\n  \"refresh_token\": \"your-refresh-token\"\n}\n```\n\n# Documentation\n\n## Authentication methods\n\n### SignInEmailPassword\n\n#### Inputs\n\n| **Property** | **Example**           |\n| ------------ | --------------------- |\n| email        | `user@yourdomain.com` |\n| password     | `yourpassword`        |\n\n#### Options\n\n| **Option**   | **Default value**                |\n| ------------ | -------------------------------- |\n| hashPassword | `SignInEmailPassword.brcyptHash` |\n\n### LoginEmailPassword\n\n#### Inputs\n\n| **Property** | **Example**           |\n| ------------ | --------------------- |\n| email        | `user@yourdomain.com` |\n| password     | `yourpassword`        |\n\n#### Options\n\n| **Option**      | **Default value**                             |\n| --------------- | --------------------------------------------- |\n| comparePassword | `LoginEmailPassword.bcryptPasswordComparison` |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbpisano%2Fnestjs-easy-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbpisano%2Fnestjs-easy-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbpisano%2Fnestjs-easy-auth/lists"}