# fastify-firebase

> Fastify v5+ plugin for firebase-admin with TypeScript support, ADC, custom app names, and auto-cleanup

Latest version **3.0.0** (published 2026-04-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install fastify-firebase
pnpm add fastify-firebase
yarn add fastify-firebase
bun add fastify-firebase
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2026-04-06 |
| First published | 2022-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 2 |
| Unpacked size | 16 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Danny Braunstein |
| Maintainers | dannybraunstein |
| Keywords | fastify, fastify-plugin, firebase, firebase-admin, firestore, auth, authentication, google-cloud, cloud-functions, cloud-run, realtime-database, cloud-storage, typescript |

## Links

- npm: https://www.npmjs.com/package/fastify-firebase
- Repository: https://github.com/dannyblv/fastify-firebase
- Homepage: https://github.com/dannyblv/fastify-firebase#readme
- Issues: https://github.com/dannyblv/fastify-firebase/issues
- npm.io page: https://npm.io/package/fastify-firebase

## Dependencies (2)

- [fastify-plugin](https://npm.io/package/fastify-plugin.md) ^5.1.0
- [firebase-admin](https://npm.io/package/firebase-admin.md) ^13.7.0

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 3.0.0 (latest) — 2026-04-06
- 2.0.1 — 2025-06-01
- 2.0.0 — 2025-06-01
- 1.1.1 — 2024-07-14
- 1.1.0 — 2023-12-23
- 1.0.3 — 2022-09-26
- 1.0.2 — 2022-09-26
- 1.0.1 — 2022-09-26
- 1.0.0 — 2022-09-26

## README

# fastify-firebase
<img src="https://github.com/dannyblv/fastify-firebase/actions/workflows/node.js.yml/badge.svg" alt="CI status" /> <a href="https://www.npmjs.com/package/fastify-firebase" title="View this project on NPM"><img src="https://img.shields.io/npm/v/fastify-firebase" alt="NPM version" /></a> <img src="https://img.shields.io/npm/dw/fastify-firebase" alt="Weekly downloads" /> <img src="https://img.shields.io/bundlephobia/min/fastify-firebase" alt="Bundle size" />

**Fastify v5+ plugin for firebase-admin. Full TypeScript support.**

---

- Works with service account JSON **or** Application Default Credentials (GCP)
- Supports `databaseURL`, `storageBucket`, and custom app `name`
- Accepts both camelCase and snake_case cert keys
- Singleton Firebase app with auto-cleanup on close
- Zero config on Cloud Run / Cloud Functions

## Install
```sh
npm i fastify-firebase
```

## Usage

### With service account cert
```ts
import Fastify from 'fastify';
import fastifyFirebase from 'fastify-firebase';
import cert from './firebase.json';

const app = Fastify();
app.register(fastifyFirebase, cert);

app.get('/users', async (req, reply) => {
  const snapshot = await req.server.firebase.firestore().collection('Users').get();
  reply.send(snapshot.docs.map((doc) => doc.data()));
});

app.listen({port: 3000});
```

### On GCP (Cloud Run, Cloud Functions)  no cert needed
```ts
app.register(fastifyFirebase); // uses Application Default Credentials
```

### With extra options
```ts
app.register(fastifyFirebase, {
  ...cert,
  name: 'my-app',                              // custom app name (default: 'default')
  databaseURL: 'https://my-app.firebaseio.com', // for Realtime Database
  storageBucket: 'my-app.appspot.com',           // for Cloud Storage
});
```

## Options

| Option | Type | Description |
|---|---|---|
| `projectId` / `project_id` | `string` | Firebase project ID |
| `privateKey` / `private_key` | `string` | Service account private key |
| `clientEmail` / `client_email` | `string` | Service account email |
| `name` | `string` | Firebase app name (default: `'default'`) |
| `databaseURL` | `string` | Realtime Database URL |
| `storageBucket` | `string` | Cloud Storage bucket |

All options are optional when using Application Default Credentials on GCP. When providing a cert, all three cert fields are required.

## Migration from v2.x
- **BREAKING**: Registering without options **no longer throws**  uses Application Default Credentials instead
- New options: `databaseURL`, `storageBucket`
- Firebase app is now deleted on Fastify close (auto-cleanup)
- Error messages are more specific

## Migration from v1.x
- Requires Fastify v5+
- ESM-only (`import`/`export`)
- Plugin is async/Promise-based

## Links
- [Generate a private key](https://firebase.google.com/docs/admin/setup#node.js)
- [Firebase Console - Service Accounts](https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk)
- [Fastify](https://www.fastify.io/) · [fastify-plugin](https://www.npmjs.com/package/fastify-plugin) · [firebase-admin](https://www.npmjs.com/package/firebase-admin)

## License
[MIT](./LICENSE)

---
_Source: https://npm.io/package/fastify-firebase · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
