npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@reyco1/nestjs-firebase

v1.0.7

Published

Firebase integration module for NestJS including authentication and Firestore

Downloads

6

Readme

@reyco1/nestjs-firebase

A streamlined NestJS module that provides Firebase integration, including authentication, Firestore access, and Firebase Admin SDK initialization. This package simplifies the integration of Firebase services into your NestJS application with type-safe decorators and guards.

Features

  • 🔥 Firebase Admin SDK initialization with async configuration
  • 🔒 Built-in authentication guard
  • 🎯 Type-safe user decorators
  • 📚 Easy access to Firestore, Auth, and Admin App instances
  • 🔄 NestJS ConfigService integration

Installation

npm install @reyco1/nestjs-firebase

Dependencies

This package has the following peer dependencies:

  • @nestjs/common: ^11.0.8
  • @nestjs/core: ^11.0.8
  • @nestjs/config: ^4.0.0
  • firebase-admin: ^13.1.0

Quick Start

  1. Download your Firebase service account key JSON file from the Firebase Console.

  2. Configure the Firebase module in your app.module.ts:

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { FirebaseModule } from '@reyco1/nestjs-firebase';

@Module({
  imports: [
    ConfigModule.forRoot(),
    FirebaseModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => ({
        serviceAccountPath: configService.get<string>('FIREBASE_SERVICE_ACCOUNT_PATH'),
      }),
      inject: [ConfigService],
    }),
  ],
})
export class AppModule {}
  1. Use the guard and decorators to protect your routes:
import { Controller, Get, UseGuards } from '@nestjs/common';
import { FirebaseAuthGuard, User, UserId } from '@reyco1/nestjs-firebase';

@Controller('protected')
@UseGuards(FirebaseAuthGuard)
export class ProtectedController {
  @Get()
  getProtectedResource(
    @UserId() userId: string,
    @User() user: FirebaseUser
  ) {
    return {
      message: 'This is protected',
      userId,
      userEmail: user.email
    };
  }
}

API Reference

Module Configuration

Async Configuration with ConfigService

FirebaseModule.forRootAsync({
  imports: [ConfigModule],
  useFactory: (configService: ConfigService) => ({
    serviceAccountPath: configService.get<string>('FIREBASE_SERVICE_ACCOUNT_PATH'),
  }),
  inject: [ConfigService],
})

Direct Configuration

FirebaseModule.forRoot({
  serviceAccountPath: './path/to/serviceAccountKey.json',
})

FirebaseService

The FirebaseService provides direct access to Firebase Admin SDK instances:

import { Injectable } from '@nestjs/common';
import { FirebaseService } from '@reyco1/nestjs-firebase';

@Injectable()
export class YourService {
  constructor(private firebaseService: FirebaseService) {}

  async someMethod() {
    // Access Firebase Admin instances
    const app = this.firebaseService.app;
    const auth = this.firebaseService.auth;
    const firestore = this.firebaseService.firestore;
  }
}

Guards

FirebaseAuthGuard

Protects routes by validating Firebase ID tokens:

@UseGuards(FirebaseAuthGuard)
@Get()
protectedRoute() {
  return 'This route is protected';
}

Decorators

@User()

// Get full user object
@User() user: FirebaseUser

// Get specific user property
@User('email') email: string

@UserId()

@UserId() userId: string

Interfaces

FirebaseUser

interface FirebaseUser {
  uid: string;
  email?: string;
  displayName?: string;
  photoURL?: string;
  phoneNumber?: string;
  disabled?: boolean;
  emailVerified?: boolean;
  metadata?: {
    creationTime?: string;
    lastSignInTime?: string;
  };
  customClaims?: { [key: string]: any };
  [key: string]: any;
}

Security Best Practices

  1. Environment Variables: Store your service account path in environment variables:
FIREBASE_SERVICE_ACCOUNT_PATH=./serviceAccountKey.json
  1. Service Account Security: Never commit your service account key to version control. Add to .gitignore:
serviceAccountKey.json
*-service-account.json
firebase-adminsdk.json

Error Handling

The package throws standard NestJS exceptions:

  • UnauthorizedException: Invalid or missing token
  • Error initializing Firebase Admin SDK
  • Invalid service account configuration

TypeScript Support

This package is written in TypeScript and includes type definitions. No additional @types packages are required.

License 📄

MIT


Made with ❤️ by Reyco1