> ## Documentation Index
> Fetch the complete documentation index at: https://docs.corsair.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Firebase plugin

> Cloud Firestore documents, queries, transactions, indexes, backups and import/export; Authentication users, sign-in, tenants, providers and project config; Realtime Database data, rules and instances; Cloud Storage objects and buckets; Hosting sites, versions, releases, channels and domains; Remote Config; Cloud Messaging; App Distribution; Security Rules; App Check; and the Firebase Management API for projects and apps (405 operations).

Use **Firebase** through Corsair: one client, typed API calls.

Connect with a service account's JSON key (Firebase console > Project
settings > Service accounts > Generate new private key), stored whole as
the key. The plugin signs a JWT with it and trades it at
oauth2.googleapis.com for an access token (scopes cloud-platform,
firebase, firebase.database, firebase.messaging, userinfo.email), cached
until a minute before it expires. A ready OAuth access token works too.
Give the service account the roles the calls need (Firebase Admin covers
most).

* **Resource names.** Google's APIs address everything by its full name:
  `projects/<project>/databases/(default)/documents/users/ada`,
  `projects/<project>/sites/<site>`, `projects/<project>/apps/<app>`. Pass
  them whole in `name` or `parent`; slashes are kept.
* **Groups.** `firestore.*` (documents, queries, transactions, indexes,
  databases, backups), `auth.*` (Identity Toolkit v1: users and sign-in) and
  `authAdmin.*` (v2: project config, tenants, providers), `database.*` (the
  Realtime Database's data and rules, by `databaseUrl`) and
  `databaseInstances.*`, `storage.*` (Cloud Storage objects and buckets;
  `storage.objects.insert` with `file` uploads, `storage.objects.download`
  returns the bytes) and `storageBuckets.*`, `hosting.*`, `remoteConfig.*`,
  `messaging.*` (FCM v1), `appDistribution.*`, `rules.*`, `appCheck.*` and
  `management.*` (projects and apps).
* **Lists** page with `pageSize` and `pageToken`; pass the response's
  `nextPageToken` for the next page. Cloud Storage lists (`storage.*`) take
  `maxResults` instead of `pageSize`.
* **Client sign-in calls** (`auth.accounts.*`, `auth.getPublicKeys` and
  the other top-level `auth.get*` reads) take the project's Web API key as
  `apiKey` (Project settings > General).
* **Remote Config.** The get operations return the template's `etag`;
  pass it as `ifMatch` when you publish, so a change someone published in
  between is refused instead of overwritten.
* **Emulators.** `emulatorUrls` in the plugin options points groups at the
  Firebase Local Emulator Suite (calls then send `Bearer owner`).
* **Risk.** Reads (GETs and the POSTs that only read, such as
  `runQuery` and `accounts.lookup`) are `read`. Deletes, sends (FCM
  messages, email and SMS codes including MFA starts, tester invitations),
  bulk document deletes, bucket retention locks, imports, restores
  and rollbacks, publishing Remote Config, rules and Hosting releases,
  writing a whole Realtime Database path (`database.set`) or its rules,
  adding Firebase or Analytics to a project and minting credentials are
  `destructive`; other writes are `write`.
* Not wrapped: Firestore's streaming Listen and Write RPCs, Cloud Storage
  push channels, and the rest of Cloud Storage (ACLs, HMAC keys, caches,
  folders, notifications), Data Connect, App Hosting, Crashlytics and ML.

**What you get:**

* 405 typed API operations

## Setup

**1. Install**

```bash npm theme={null}
npm install corsair @corsair-dev/firebase better-sqlite3
npm install --save-dev @types/better-sqlite3
```

```bash yarn theme={null}
yarn add corsair @corsair-dev/firebase better-sqlite3
yarn add --dev @types/better-sqlite3
```

```bash pnpm theme={null}
pnpm install corsair @corsair-dev/firebase better-sqlite3
pnpm install --save-dev @types/better-sqlite3
```

```bash bun theme={null}
bun add corsair @corsair-dev/firebase better-sqlite3
bun add --dev @types/better-sqlite3
```

**2. Add the plugin**

```ts corsair.ts theme={null}
import Database from 'better-sqlite3';
import { createCorsair } from 'corsair';
import { firebase } from '@corsair-dev/firebase';

export const corsair = createCorsair({
	plugins: [
		firebase(),
	],
	database: new Database('corsair.db'),
	kek: process.env.CORSAIR_KEK!,
	multiTenancy: true,
	hub: {
		projectApiKey: process.env.CORSAIR_API_KEY!,
		signingSecret: process.env.CORSAIR_SIGNING_SECRET!,
	},
});
```

With `multiTenancy: true`, scope calls with `corsair.withTenant(id)`. See [Quick start](https://docs.corsair.dev/quick-start.md) for KEK + Hub keys, and [Multi-tenancy](https://docs.corsair.dev/concepts/multi-tenancy.md) for account isolation.

**3. Choose authentication**

> [tab] API Key (Recommended)
>
> Store the Firebase API key before the first call: `pnpm corsair setup --plugin=firebase --tenant=acme api_key=<your-key>` (leave out `--tenant` without `multiTenancy`), or pass it as `key` in the plugin options. With Hub, each tenant enters their own key on the connect page. See [API key auth](https://docs.corsair.dev/concepts/api-key).
>
> ```ts theme={null}
> firebase()
> ```
>
> More: [API Key](https://docs.corsair.dev/concepts/api-key)

**4. Connect a tenant**

Mint a connect link and send the tenant to it. Hub hosts the page and delivers the result to your app — see [Connect / OAuth](https://docs.corsair.dev/management/connect).

```ts theme={null}
const { connectUrl } = await corsair.manage.connect.createLink({
	plugin: 'firebase',
	tenantId: 'acme',
});
// redirect the user's browser to connectUrl
```

## Example API calls

**Get a Firestore document**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.firebase.api.firestore.databases.documents.get({ name: 'projects/demo-project/databases/(default)/documents/users/ada' });
```

**Write to the Realtime Database**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.firebase.api.database.set({
	databaseUrl: 'https://demo-project-default-rtdb.firebaseio.com',
	path: 'users/ada',
	data: { name: 'Ada', born: 1815 },
});
```

See the full list on the [API](https://docs.corsair.dev/plugins/firebase/api.md) page.

## What's next

> [card] [API reference](https://docs.corsair.dev/plugins/firebase/api.md)
>
> Every `firebase.api.*` operation with input and output types.

> [card] [Connect / OAuth](https://docs.corsair.dev/management/connect)
>
> createLink, Hub delivery, and tenant connect flows.

> [card] [Use with agents](https://docs.corsair.dev/mcp-adapters/mcp-adapters)
>
> Expose this plugin's operations as MCP tools.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.