RealComposer
Next.js / ReactContentfulSecurity & Secret Vault

Hide contentful preview token in nextjs app

Preview mode without public preview secrets

Direct Answer & Architecture Summary

Edge injects preview token; ISR pages fetch composed CMS JSON safely. For "hide contentful preview token in nextjs app", store CONTENTFUL_PREVIEW_TOKEN in Secret Vault, call https://preview.contentful.com/spaces/{{query.spaceId}}/entries from a Worker, and let Next.js / React hit only https://realcomposer.com/v1/workspace/hide-contentful-preview-token-nextjs 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 Contentful credentials

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

Critical Security & Operational Risks:
  • Production Contentful 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

Bind vault keys to the Worker

Store CONTENTFUL_PREVIEW_TOKEN in the vault. Next.js / React never embeds the raw secret, only a revocable rc_live_ client token.

2

Configure upstream steps and output mapping

Point step contentful at https://preview.contentful.com/spaces/{{query.spaceId}}/entries 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/hide-contentful-preview-token-nextjs', {
  cache: 'no-store',
  headers: { Authorization: 'Bearer rc_live_your_token' }
});
                  
Payload Slimming Comparison
85% Bandwidth Reduction
Raw Upstream Response255 B
              {
  "requestId": "req_hide-con",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "hide-contentful-preview-token-nextjs"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
            
RealComposer Slimmed Edge Payload37 B
              {
  "entryId": "sample",
  "title": "sample"
}
            

Recipe Specs

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

Developer Questions & Troubleshooting

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

Store CONTENTFUL_PREVIEW_TOKEN for hide-contentful-preview-token-nextjs. Next.js / React never sees decrypted values.

When does edge caching apply to this recipe?

hide-contentful-preview-token-nextjs forwards client JSON to POST upstreams unchanged; secrets interpolate only in URLs and header templates.

What happens if an upstream step times out?

Allowed origins on the hide-contentful-preview-token-nextjs client token restrict which domains may call the edge URL.

Sources & Definitions Used in This Answer

Instant Deployment

Deploy this Next.js / React + Contentful 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