RealComposer
Client PlatformsOfficial Vue docs

Vue Safe & Unsafe Practices

Direct Answer

Vue single-page apps run in the browser and Vite inlines every VITE_ variable into the bundle. Keep secret keys out of Vue code, avoid v-html on untrusted content, and call private APIs through a server or edge proxy.

Credentials & Where They Belong

Client safe
VITE_ variables

Public by design.

Server only
Secret API keys

Must live in a proxy.

Safe Practices

  • Use text interpolation for API content

    Mustache syntax escapes HTML. Sanitize with a library before any v-html.

  • Centralize API calls in one client module

    A single fetch wrapper makes it easy to attach client tokens and point at a proxy.

Unsafe Practices

  • Storing secrets in VITE_ variables

    They appear in the built JavaScript files.

  • Rendering CMS HTML with v-html unsanitized

    Injected scripts can steal tokens from the page.

The RealComposer Pattern

Configure allowed origins on a RealComposer pipeline and fetch it from Vue with a client token, keeping upstream keys in the vault.

START BUILDING FREE

Frequently Asked Questions

Q:Can a Vue SPA keep an API key secret?

No. Everything in the SPA bundle is public. Use a proxy for secret calls.

Security & Secret Vault

Protect API Key in Vue SPA

To solve protect api key in vue spa, never execute unauthenticated requests or embed private tokens directly in client bundles. RealComposer acts as a sub-10ms edge gateway running on Cloudflare Workers that securely injects credentials from your Secret Vault, normalizes responses, and prevents unauthorized API usage. Route calls through your RealComposer edge URL to guarantee complete privacy, robust origin validation, and low mobile latency.

Sub-10ms edgeView Recipe

Related Concepts