{"id":13818181,"url":"https://github.com/tfarras/nestjs-firebase-auth","last_synced_at":"2025-05-05T22:10:33.049Z","repository":{"id":46198318,"uuid":"254951352","full_name":"tfarras/nestjs-firebase-auth","owner":"tfarras","description":"Firebase Authentication Strategy for NestJS Passport Integration","archived":false,"fork":false,"pushed_at":"2024-03-05T07:41:56.000Z","size":14,"stargazers_count":68,"open_issues_count":3,"forks_count":26,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-05T10:33:47.663Z","etag":null,"topics":["firebase","nestjs","typescript"],"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/tfarras.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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}},"created_at":"2020-04-11T20:38:56.000Z","updated_at":"2024-08-21T12:40:39.000Z","dependencies_parsed_at":"2024-06-18T19:14:49.593Z","dependency_job_id":"f582b7b8-4025-49dd-b400-fb7e30cbc1cc","html_url":"https://github.com/tfarras/nestjs-firebase-auth","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfarras%2Fnestjs-firebase-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfarras%2Fnestjs-firebase-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfarras%2Fnestjs-firebase-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfarras%2Fnestjs-firebase-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tfarras","download_url":"https://codeload.github.com/tfarras/nestjs-firebase-auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252584329,"owners_count":21771945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["firebase","nestjs","typescript"],"created_at":"2024-08-04T07:00:35.192Z","updated_at":"2025-05-05T22:10:33.033Z","avatar_url":"https://github.com/tfarras.png","language":"TypeScript","funding_links":[],"categories":["Integrations"],"sub_categories":[],"readme":"#\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"http://nestjs.com/\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://nestjs.com/img/logo_text.svg\" width=\"150\" alt=\"Nest Logo\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003ch3 align=\"center\"\u003eNestJS Passport Strategy for Firebase Auth using Firebase Admin SDK\u003c/h3\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://nestjs.com\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/built%20with-NestJs-red.svg\" alt=\"Built with NestJS\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n# Installation\n\n## Install peer dependencies\n\n```bash\nnpm install passport passport-jwt\nnpm install --save-dev @types/passport-jwt\n```\n\n## Install `@nestjs/passport` for authentication\n\n```bash\nnpm install @nestjs/passport\n```\n\n## Install strategy\n\n```bash\nnpm install @tfarras/nestjs-firebase-auth\n```\n\n# Important\n\nTo work with Firebase Auth you need to configure and initialize your firebase app. For this purpose you can use my [module for firebase-admin](https://github.com/tfarras/nestjs-firebase-admin).\n\n# Create strategy\n\n```typescript\nimport { Injectable } from \"@nestjs/common\";\nimport { PassportStrategy } from \"@nestjs/passport\";\nimport { ExtractJwt } from 'passport-jwt';\nimport { FirebaseAuthStrategy } from '@tfarras/nestjs-firebase-auth';\n\n@Injectable()\nexport class FirebaseStrategy extends PassportStrategy(FirebaseAuthStrategy, 'firebase') {\n  public constructor() {\n    super({\n      extractor: ExtractJwt.fromAuthHeaderAsBearerToken(),\n    });\n  }\n}\n```\n\nNote: You should provide an extractor. More information about passport-jwt extractors you can find here: [http://www.passportjs.org/packages/passport-jwt/#included-extractors](http://www.passportjs.org/packages/passport-jwt/#included-extractors)\n\n# Create `AuthModule` and provide created strategy\n\n```typescript\nimport { Module } from \"@nestjs/common\";\nimport { PassportModule } from \"@nestjs/passport\";\nimport { FirebaseStrategy } from \"./firebase.strategy\";\n\n@Module({\n  imports: [PassportModule],\n  providers: [FirebaseStrategy],\n  exports: [FirebaseStrategy],\n  controllers: [],\n})\nexport class AuthModule { }\n```\n\n# Import `AuthModule` into `AppModule`\n\n```typescript\nimport { FirebaseAdminCoreModule } from '@tfarras/nestjs-firebase-admin';\nimport { Module } from '@nestjs/common';\nimport { ConfigModule, ConfigService } from 'nestjs-config';\nimport { AppController } from './app.controller';\nimport { AppService } from './app.service';\nimport { AuthModule } from './auth/auth.module';\nimport * as path from 'path';\n\n@Module({\n  imports: [\n    ConfigModule.load(path.resolve(__dirname, 'config', '**', '!(*.d).{ts,js}')),\n    FirebaseAdminCoreModule.forRootAsync({\n      useFactory: (config: ConfigService) =\u003e config.get('firebase'),\n      inject: [ConfigService],\n    }),\n    AuthModule,\n  ],\n  controllers: [AppController],\n  providers: [AppService],\n})\nexport class AppModule { }\n\n```\n\n# Protect your routes\n\n```typescript\nimport { Controller, Get, Inject, UseGuards } from '@nestjs/common';\nimport { AuthGuard } from '@nestjs/passport';\nimport { FirebaseAdminSDK, FIREBASE_ADMIN_INJECT } from '@tfarras/nestjs-firebase-admin';\nimport { AppService } from './app.service';\n\n@Controller()\nexport class AppController {\n  constructor(\n    private readonly appService: AppService,\n    @Inject(FIREBASE_ADMIN_INJECT) private readonly fireSDK: FirebaseAdminSDK,\n  ) { }\n\n  @Get()\n  @UseGuards(AuthGuard('firebase'))\n  getHello() {\n    return this.fireSDK.auth().listUsers();\n  }\n}\n\n```\n\n# Custom second validation\n\nIn cases when you want to validate also if user exists in your database, or anything else after successfull Firebase validation you can define custom `validate` method in your strategy.\n\n## Example\n\n```typescript\nimport { Injectable } from \"@nestjs/common\";\nimport { PassportStrategy } from \"@nestjs/passport\";\nimport { FirebaseAuthStrategy, FirebaseUser } from '@tfarras/nestjs-firebase-auth';\nimport { ExtractJwt } from 'passport-jwt';\n\n@Injectable()\nexport class FirebaseStrategy extends PassportStrategy(FirebaseAuthStrategy, 'firebase') {\n  public constructor() {\n    super({\n      extractor: ExtractJwt.fromAuthHeaderAsBearerToken(),\n    });\n  }\n\n  async validate(payload: FirebaseUser): Promise\u003cFirebaseUser\u003e {\n    // Do here whatever you want and return your user\n    return payload;\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftfarras%2Fnestjs-firebase-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftfarras%2Fnestjs-firebase-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftfarras%2Fnestjs-firebase-auth/lists"}