{
  "slug": "hide-api-key-vue-spa",
  "title": "Protect API Key in Vue SPA",
  "metaDescription": "Protect api key in vue spa. Keep REST API keys in RealComposer Vault; Vue / SPA uses rc_live_ tokens only. RealComposer edge vault and client tokens keep s",
  "headline": "REST API secrets stay out of Vue / SPA bundles",
  "category": "security",
  "categoryLabel": "Security & Secret Vault",
  "urgency": 9,
  "clientPlatform": "Vue / SPA",
  "upstreamServices": [
    "REST API"
  ],
  "searchIntentQuery": "protect api key in vue spa",
  "directAnswerSummary": "Vue / SPA cannot safely store REST API production keys. Vault-bound headers reach https://jsonplaceholder.typicode.com/users/{{query.userId}} on Workers while apps call your hide-api-key-vue-spa edge URL.",
  "problem": {
    "title": "Why Vue / SPA leaks REST API credentials",
    "explanation": "Attackers routinely extract REST API secrets from Vue / SPA builds. Direct browser calls also expose internal error payloads with hostnames.",
    "risks": [
      "Production REST API keys copied from Vue / SPA bundles",
      "Compliance violations after credential leaks",
      "Attackers replaying vault-grade scopes from a laptop"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Bind vault keys to the Worker",
      "description": "Create API_BEARER_TOKEN vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders."
    },
    {
      "stepNumber": 2,
      "title": "Set headers, mapping, and cache TTL",
      "description": "Point step upstream at https://jsonplaceholder.typicode.com/users/{{query.userId}} 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)."
    },
    {
      "stepNumber": 3,
      "title": "Call from Vue / SPA",
      "description": "Call https://realcomposer.com/v1/workspace/hide-api-key-vue-spa with a restricted rc_live_ client token. Vue / SPA never sends upstream secrets.",
      "codeSnippet": "const { data } = await useFetch('https://realcomposer.com/v1/workspace/hide-api-key-vue-spa', {\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "Protect API Key in Vue SPA",
    "method": "GET",
    "cacheTtlSeconds": 0,
    "authMode": "client_token",
    "steps": [
      {
        "stepKey": "upstream",
        "upstreamUrlTemplate": "https://jsonplaceholder.typicode.com/users/{{query.userId}}",
        "httpMethod": "GET",
        "headersTemplate": {
          "Authorization": "Bearer {{secrets.API_BEARER_TOKEN}}"
        },
        "timeoutMs": 3000
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "userId",
          "sourcePath": "id",
          "type": "number",
          "sourceStep": "upstream"
        },
        {
          "targetPath": "name",
          "sourcePath": "name",
          "type": "string",
          "sourceStep": "upstream"
        },
        {
          "targetPath": "email",
          "sourcePath": "email",
          "type": "string",
          "sourceStep": "upstream"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_hide-api",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "hide-api-key-vue-spa"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "userId": "sample",
    "name": "sample",
    "email": "sample"
  },
  "curlSnippet": "curl -X GET \"https://realcomposer.com/v1/workspace/hide-api-key-vue-spa\" \\\n  -H \"Authorization: Bearer rc_live_client_token\"",
  "faqs": [
    {
      "question": "Can Vue / SPA call REST API without holding the production key?",
      "answer": "Use scoped tokens where the vendor allows them on hide-api-key-vue-spa. Admin keys stay {{secrets.*}} references only."
    },
    {
      "question": "How do I forward JSON bodies to POST upstreams?",
      "answer": "hide-api-key-vue-spa POST steps bypass caches.default even if cacheTtlSeconds is set in the dashboard."
    },
    {
      "question": "How do I rotate upstream credentials?",
      "answer": "Allowed origins on the hide-api-key-vue-spa client token restrict which domains may call the edge URL."
    }
  ],
  "relatedRecipeSlugs": [
    "reduce-json-payload-size-frontend",
    "anthropic-claude-api-frontend-proxy",
    "connect-stripe-to-retool-securely"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/hide-api-key-vue-spa",
    "markdown": "https://realcomposer.com/recipes/hide-api-key-vue-spa.md",
    "json": "https://realcomposer.com/recipes/hide-api-key-vue-spa.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=hide-api-key-vue-spa&via=agent"
  }
}