RealComposer
Next.js / ReactFirebaseSecurity & Secret Vault

Call firebase admin api from nextjs without exposing service account

Firebase Admin calls only from the edge

Direct Answer & Architecture Summary

Store service account JSON in Vault; Next.js routes call RealComposer instead of Firebase Admin SDK in serverless bundles. For "call firebase admin api from nextjs without exposing service account", 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 Next.js / React hit only https://realcomposer.com/v1/workspace/call-firebase-admin-from-nextjs-securely with an rc_live_ client token.

Security LevelAES-256-GCM Vault
Edge LatencySub-10ms Response
InfrastructureZero Server Maintenance
The Problem Solved

Why Next.js / React leaks Firebase credentials

Attackers routinely extract Firebase secrets from Next.js / React builds. Direct browser calls also expose internal error payloads with hostnames.

Critical Security & Operational Risks:
  • Production Firebase keys copied from Next.js / React bundles
  • Compliance violations after credential leaks
  • Attackers replaying vault-grade scopes from a laptop
Architecture & Step-by-Step Implementation

How RealComposer Solves This at the Edge

1

Add vault secrets for this pipeline

Add FIREBASE_ACCESS_TOKEN to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream.

2

Target the real upstream URL

Point step firebase at https://firestore.googleapis.com/v1/projects/{{query.projectId}}/databases/(default)/documents/{{query.collection}}/{{query.docId}} with GET. Add output mapping fields that mirror the JSON contract your screen already expects. 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 Next.js / React

Allowed origins on the token should list every Next.js / React host that calls this URL.

                    // app/api route or client component
const res = await fetch('https://realcomposer.com/v1/workspace/call-firebase-admin-from-nextjs-securely', {
  cache: 'no-store',
  headers: { Authorization: 'Bearer rc_live_your_token' }
});
                  
Payload Slimming Comparison
85% Bandwidth Reduction
Raw Upstream Response259 B
              {
  "requestId": "req_call-fir",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "call-firebase-admin-from-nextjs-securely"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
            
RealComposer Slimmed Edge Payload38 B
              {
  "docName": "sample",
  "fields": "sample"
}
            

Recipe Specs

HTTP method
GET
Upstream calls
1
Edge cache TTL
No caching
Client auth
Restricted client token
Mapped output fields
2
Payload
259 B to 38 B (-85%)
Call from Terminal or Client
curl -X GET "https://realcomposer.com/v1/workspace/call-firebase-admin-from-nextjs-securely" \
  -H "Authorization: Bearer rc_live_client_token"
Frequently Asked Questions

Developer Questions & Troubleshooting

Does Next.js / React need CORS changes after adding RealComposer?

Log request IDs for call-firebase-admin-from-nextjs-securely, not raw Firebase payloads, because upstream bodies may include PII.

What cache key does RealComposer use?

call-firebase-admin-from-nextjs-securely keeps cache TTL at 0 because it uses POST upstream calls or per-user responses. Add ids to query strings before enabling GET cache.

Can I restrict which domains call this pipeline?

Rotate vault secrets for call-firebase-admin-from-nextjs-securely anytime; clients keep the same rc_live_ token.

Sources & Definitions Used in This Answer

Instant Deployment

Deploy this Next.js / React + Firebase Recipe

Clone this pre-configured pipeline into your RealComposer workspace in one click. We pre-populate upstream URLs, headers, and mapping rules.

CLONE THIS RECIPE
Related Architecture Recipes