RealComposer
Client PlatformsOfficial Next.js docs

Next.js Safe & Unsafe Practices

Direct Answer

In Next.js, any variable prefixed NEXT_PUBLIC_ is inlined into the client bundle. Secrets are safe only in Server Components, Route Handlers, and Server Actions, and every Server Action is a public endpoint that must authenticate and authorize its caller.

Credentials & Where They Belong

Client safe
NEXT_PUBLIC_ variables

Inlined at build time into browser JavaScript.

Server only
Unprefixed environment variables

Available only in server code paths.

Safe Practices

  • Import the server-only package in secret modules

    The build fails if a client component accidentally imports code that reads secrets.

  • Authorize inside every Server Action

    Check the session and ownership in the action, not just in the UI that calls it.

  • Pass minimal props to client components

    Props are serialized into the page, so strip private fields first.

Unsafe Practices

  • Prefixing secrets with NEXT_PUBLIC_

    The value ships to every visitor.

  • Passing full database rows to client components

    Hidden fields still appear in the serialized payload.

The RealComposer Pattern

Use RealComposer pipelines from client components or ISR pages for third-party aggregation, so preview tokens and upstream keys stay in the vault rather than in Next.js env files.

START BUILDING FREE

Frequently Asked Questions

Q:Are Next.js Server Actions secure by default?

No. They are reachable by direct POST requests, so each one must validate input and check authorization.

Security & Secret Vault

Call firebase admin api from nextjs without exposing service account

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.

Sub-10ms edgeView Recipe
Security & Secret Vault

Hide contentful preview token in nextjs app

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.

Sub-10ms edgeView Recipe
Security & Secret Vault

Hide anthropic api key in nextjs chat interface

Next.js client chat UI calls edge stream; Anthropic never touches browser. For "hide anthropic api key in nextjs chat interface", store ANTHROPIC_API_KEY in Secret Vault, call https://api.anthropic.com/v1/messages from a Worker, and let Next.js / React hit only https://realcomposer.com/v1/workspace/hide-anthropic-api-key-nextjs with an rc_live_ client token. POST upstream calls are not stored in caches.default; clients must send JSON bodies and headers forward unchanged.

Sub-10ms edgeView Recipe

Stitch contentful entries with shopify products api

Contentful marketing fields plus Shopify SKU inventory in parallel. For "stitch contentful entries with shopify products api", store CONTENTFUL_ACCESS_TOKEN, SHOPIFY_ACCESS_TOKEN in Secret Vault, call https://cdn.contentful.com/spaces/{{query.spaceId}}/entries from a Worker, and let Next.js / React hit only https://realcomposer.com/v1/workspace/stitch-contentful-with-shopify-products with an rc_live_ client token.

Sub-10ms edgeView Recipe

Merge cloudinary assets with contentful entries

Resolve Contentful asset references with Cloudinary transformation metadata. For "merge cloudinary assets with contentful entries", store CLOUDINARY_BASIC_AUTH, CONTENTFUL_ACCESS_TOKEN in Secret Vault, call https://api.cloudinary.com/v1_1/{{secrets.CLOUDINARY_CLOUD_NAME}}/resources/image from a Worker, and let Next.js / React hit only https://realcomposer.com/v1/workspace/merge-cloudinary-with-contentful-entries with an rc_live_ client token.

Sub-10ms edgeView Recipe

Related Concepts