# Stitch firebase with clerk session bootstrap

> Clerk session and Firebase FCM registration merged at startup. For "stitch firebase with clerk session bootstrap", store FIREBASE_ACCESS_TOKEN, CLERK_SECRET_KEY in Secret Vault, call https://firestore.googleapis.com/v1/projects/{{query.projectId}}/databases/(default)/documents/{{query.collection}}/{{query.docId}} from a Worker, and let React Native hit only https://realcomposer.com/v1/workspace/stitch-firebase-with-clerk-bootstrap with an rc_live_ client token.

- Canonical page: https://realcomposer.com/recipes/stitch-firebase-with-clerk-bootstrap
- Client platform: React Native
- Upstream services: Firebase, Clerk
- Category: Multi-API Aggregation
- JSON version: https://realcomposer.com/recipes/stitch-firebase-with-clerk-bootstrap.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=stitch-firebase-with-clerk-bootstrap&via=agent

## Problem: Serial Firebase and Clerk calls slow React Native pages

Each extra Firebase and Clerk hop adds hundreds of milliseconds and another OAuth refresh path your UI must manage.

- One slow upstream blocking an entire page
- Partial failures leaving UI in inconsistent states
- Duplicate auth refresh logic per service

## Solution steps

1. **Add vault secrets for this pipeline**: Add FIREBASE_ACCESS_TOKEN, CLERK_SECRET_KEY to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream.

2. **Set headers, mapping, and cache TTL**: Use GET against https://firestore.googleapis.com/v1/projects/{{query.projectId}}/databases/(default)/documents/{{query.collection}}/{{query.docId}}. Allowed origins on the client token should match leave cache ttl at 0 when each response is user-specific (include userid or record id in query params before enabling cache).

3. **Call from React Native**: Call https://realcomposer.com/v1/workspace/stitch-firebase-with-clerk-bootstrap with a restricted rc_live_ client token. React Native never sends upstream secrets.

```
const res = await fetch('https://realcomposer.com/v1/workspace/stitch-firebase-with-clerk-bootstrap', {
  headers: { Authorization: 'Bearer rc_live_your_token' }
});
```

## Pipeline config

Import this config into a RealComposer pipeline. `{{secrets.NAME}}` values are read from the encrypted Secret Vault at request time, so the client never sees them.

```json
{
  "name": "Stitch firebase with clerk session bootstrap",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "firebase",
      "upstreamUrlTemplate": "https://firestore.googleapis.com/v1/projects/{{query.projectId}}/databases/(default)/documents/{{query.collection}}/{{query.docId}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.FIREBASE_ACCESS_TOKEN}}"
      },
      "timeoutMs": 3000
    },
    {
      "stepKey": "clerk",
      "upstreamUrlTemplate": "https://api.clerk.com/v1/users/{{query.userId}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.CLERK_SECRET_KEY}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "firebase.docName",
        "sourcePath": "name",
        "type": "string",
        "sourceStep": "firebase"
      },
      {
        "targetPath": "firebase.fields",
        "sourcePath": "fields",
        "type": "object",
        "sourceStep": "firebase"
      },
      {
        "targetPath": "clerk.userId",
        "sourcePath": "id",
        "type": "string",
        "sourceStep": "clerk"
      },
      {
        "targetPath": "clerk.email",
        "sourcePath": "email_addresses.0.email_address",
        "type": "string",
        "sourceStep": "clerk"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/stitch-firebase-with-clerk-bootstrap" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_stitch-f",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "stitch-firebase-with-clerk-bootstrap"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "firebase_docName": "sample",
  "firebase_fields": "sample",
  "clerk_userId": "sample",
  "clerk_email": "sample"
}
```

## FAQ

### What should React Native store instead of Firebase secrets?

Yes for stitch-firebase-with-clerk-bootstrap. Ship only an rc_live_ client token in React Native; RealComposer injects FIREBASE_ACCESS_TOKEN on https://firestore.googleapis.com/v1/projects/{{query.projectId}}/databases/(default)/documents/{{query.collection}}/{{query.docId}}.

### Will Anthropic or Linear prompt bodies be rewritten?

stitch-firebase-with-clerk-bootstrap POST steps bypass caches.default even if cacheTtlSeconds is set in the dashboard.

### What happens if an upstream step times out?

Rotate vault secrets for stitch-firebase-with-clerk-bootstrap anytime; clients keep the same rc_live_ token.
