# Combine firebase auth user with supabase profile endpoint

> Firebase ID token lookup and Supabase profile row merged at edge. For "combine firebase auth user with supabase profile endpoint", store FIREBASE_ACCESS_TOKEN, SUPABASE_SERVICE_ROLE_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 / Flutter / Mobile hit only https://realcomposer.com/v1/workspace/combine-firebase-auth-with-supabase-profile with an rc_live_ client token.

- Canonical page: https://realcomposer.com/recipes/combine-firebase-auth-with-supabase-profile
- Client platform: React / Flutter / Mobile
- Upstream services: Firebase, Supabase
- Category: Multi-API Aggregation
- JSON version: https://realcomposer.com/recipes/combine-firebase-auth-with-supabase-profile.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=combine-firebase-auth-with-supabase-profile&via=agent

## Problem: Waterfall latency from multiple Firebase and Supabase requests

React / Flutter / Mobile widgets often await Firebase and Supabase sequentially, multiplying TLS handshakes on cellular networks and amplifying failure rates.

- Race conditions between parallel manual fetches
- Higher mobile data usage from redundant JSON
- Timeouts when any upstream exceeds cellular RTT

## Solution steps

1. **Store upstream credentials in Secret Vault**: Store FIREBASE_ACCESS_TOKEN, SUPABASE_SERVICE_ROLE_KEY in the vault. React / Flutter / Mobile never embeds the raw secret, only a revocable rc_live_ client token.

2. **Set headers, mapping, and cache TTL**: Configure headersTemplate to inject vault secrets, target https://firestore.googleapis.com/v1/projects/{{query.projectId}}/databases/(default)/documents/{{query.collection}}/{{query.docId}}, and Add output mapping fields that mirror the JSON contract your screen already expects.

3. **Call from React / Flutter / Mobile**: Authorize with Bearer rc_live_ and fetch the mapped JSON contract your UI already expects.

```
const res = await fetch('https://realcomposer.com/v1/workspace/combine-firebase-auth-with-supabase-profile', {
  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": "Combine firebase auth user with supabase profile endpoint",
  "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": "supabase",
      "upstreamUrlTemplate": "https://{{secrets.SUPABASE_PROJECT_REF}}.supabase.co/rest/v1/{{query.table}}?{{query.filter}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "apikey": "{{secrets.SUPABASE_SERVICE_ROLE_KEY}}",
        "Authorization": "Bearer {{secrets.SUPABASE_SERVICE_ROLE_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": "supabase.rowId",
        "sourcePath": "0.id",
        "type": "string",
        "sourceStep": "supabase"
      },
      {
        "targetPath": "supabase.email",
        "sourcePath": "0.email",
        "type": "string",
        "sourceStep": "supabase"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/combine-firebase-auth-with-supabase-profile" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_combine-",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "combine-firebase-auth-with-supabase-profile"
  },
  "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",
  "supabase_rowId": "sample",
  "supabase_email": "sample"
}
```

## FAQ

### Which Firebase credential belongs in the vault for this pipeline?

Yes for combine-firebase-auth-with-supabase-profile. Ship only an rc_live_ client token in React / Flutter / Mobile; RealComposer injects FIREBASE_ACCESS_TOKEN on https://firestore.googleapis.com/v1/projects/{{query.projectId}}/databases/(default)/documents/{{query.collection}}/{{query.docId}}.

### What cache key does RealComposer use?

combine-firebase-auth-with-supabase-profile vault headers attach server-side, but Anthropic or OpenAI model and messages must come from the client body.

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

Allowed origins on the combine-firebase-auth-with-supabase-profile client token restrict which domains may call the edge URL.
