{
  "slug": "hide-firebase-api-key-react-native",
  "title": "Hide firebase api key in react native mobile app",
  "metaTitle": "Hide firebase api key in react - RealComposer",
  "metaDescription": "Hide firebase api key in react native mobile app. Keep Firebase keys in RealComposer Vault; React Native uses rc_live_ tokens only.",
  "headline": "Mobile-safe Firebase identity and Firestore reads",
  "category": "security",
  "categoryLabel": "Security & Secret Vault",
  "urgency": 10,
  "clientPlatform": "React Native",
  "upstreamServices": [
    "Firebase"
  ],
  "searchIntentQuery": "hide firebase api key in react native mobile app",
  "directAnswerSummary": "Client uses anon rules; privileged reads run through edge proxy with Firebase tokens injected. For \"hide firebase api key in react native mobile app\", store FIREBASE_ACCESS_TOKEN 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/hide-firebase-api-key-react-native with an rc_live_ client token.",
  "problem": {
    "title": "Why React Native leaks Firebase credentials",
    "explanation": "Attackers routinely extract Firebase secrets from React Native builds. Direct browser calls also expose internal error payloads with hostnames.",
    "risks": [
      "Production Firebase keys copied from React Native bundles",
      "Compliance violations after credential leaks",
      "Attackers replaying vault-grade scopes from a laptop"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Store upstream credentials in Secret Vault",
      "description": "Create FIREBASE_ACCESS_TOKEN vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders."
    },
    {
      "stepNumber": 2,
      "title": "Configure upstream steps and output mapping",
      "description": "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)."
    },
    {
      "stepNumber": 3,
      "title": "Call from React Native",
      "description": "Authorize with Bearer rc_live_ and fetch the mapped JSON contract your UI already expects.",
      "codeSnippet": "const res = await fetch('https://realcomposer.com/v1/workspace/hide-firebase-api-key-react-native', {\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "Hide firebase api key in react native mobile app",
    "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
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "docName",
          "sourcePath": "name",
          "type": "string",
          "sourceStep": "firebase"
        },
        {
          "targetPath": "fields",
          "sourcePath": "fields",
          "type": "object",
          "sourceStep": "firebase"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_hide-fir",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "hide-firebase-api-key-react-native"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "docName": "sample",
    "fields": "sample"
  },
  "curlSnippet": "curl -X GET \"https://realcomposer.com/v1/workspace/hide-firebase-api-key-react-native\" \\\n  -H \"Authorization: Bearer rc_live_client_token\"",
  "faqs": [
    {
      "question": "What should React Native store instead of Firebase secrets?",
      "answer": "Yes for hide-firebase-api-key-react-native. 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}}."
    },
    {
      "question": "Will Anthropic or Linear prompt bodies be rewritten?",
      "answer": "Cache key for hide-firebase-api-key-react-native: internal edge-cache path plus sorted query. Identical params hit; vary userId per user."
    },
    {
      "question": "Can I restrict which domains call this pipeline?",
      "answer": "Upstream steps in hide-firebase-api-key-react-native honor timeoutMs and optional fallback JSON without leaking secrets."
    }
  ],
  "relatedRecipeSlugs": [
    "stripe-proxy-react-native",
    "posthog-mobile-proxy"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/hide-firebase-api-key-react-native",
    "markdown": "https://realcomposer.com/recipes/hide-firebase-api-key-react-native.md",
    "json": "https://realcomposer.com/recipes/hide-firebase-api-key-react-native.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=hide-firebase-api-key-react-native&via=agent"
  }
}