{"record":{"id":"7e98ed3a3efe950a","repo":"cube-js/cube","slug":"live-preview-token-is-invalid","errorCode":null,"errorMessage":"Live-preview token is invalid","messagePattern":"Live-preview token is invalid","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-backend-cloud/src/live-preview.ts","lineNumber":39,"sourceCode":"  private lastHash: string | undefined;\n\n  private log(message: string) {\n    console.log('☁️  Live-preview:', message);\n  }\n\n  public setAuth(token: string): AuthObject {\n    try {\n      const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());\n      this.auth = {\n        auth: token,\n        deploymentId: payload.deploymentId,\n        url: payload.url,\n      };\n\n      return this.auth;\n    } catch (e: any) {\n      internalExceptions(e);\n      throw new Error('Live-preview token is invalid');\n    }\n  }\n\n  public startWatch(): void {\n    if (!this.auth) {\n      throw new Error('Auth isn\\'t set');\n    }\n\n    if (!this.watcher) {\n      this.log('Start with Cube Cloud');\n      this.watcher = chokidar.watch(\n        process.cwd(),\n        {\n          ignoreInitial: false,\n          ignored: [\n            '**/node_modules/**',\n            '**/.*'\n          ]","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-backend-cloud/src/live-preview.ts#L21-L57","documentation":"LivePreviewWatcher.setAuth decodes the middle segment of a JWT-style token (base64 JSON) to extract deploymentId and url. If JSON.parse or Buffer decoding fails — meaning the token is malformed, truncated, or not a JWT — it logs the internal exception and throws 'Live-preview token is invalid'.","triggerScenarios":"Calling setAuth with a value that has no dot-separated base64 JSON payload: an empty string, an API key instead of a JWT, a truncated token, or a token copied with whitespace/quotes.","commonSituations":"Copy-pasting the wrong credential type (e.g. a deploy auth token instead of a live-preview JWT) into the live-preview token prompt; terminal wrapping breaking the token across lines; missing env var yielding an empty string.","solutions":["Copy the full live-preview JWT from the Cube Cloud UI on one line, without quotes or trailing whitespace.","Verify the token has the JWT form header.payload.signature and base64-decode the payload to confirm deploymentId/url are present.","Set the token via the proper env var/config rather than manual paste to avoid truncation.","Obtain a fresh live-preview token from Cube Cloud if the old one was revoked."],"exampleFix":"// before\nwatcher.setAuth(process.env.CUBE_CLOUD_TOKEN ?? ''); // empty -> invalid\n// after\nconst token = process.env.CUBE_LIVE_PREVIEW_TOKEN;\nif (!token || token.split('.').length !== 3) throw new Error('CUBE_LIVE_PREVIEW_TOKEN must be a JWT');\nwatcher.setAuth(token);","handlingStrategy":"validation","validationCode":"function looksLikeJwt(token: string | undefined): boolean {\n  if (!token || token.split('.').length !== 3) return false;\n  try {\n    const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());\n    return !!payload.deploymentId && !!payload.url;\n  } catch { return false; }\n}\n// usage: if (!looksLikeJwt(process.env.CUBE_LIVE_PREVIEW_TOKEN)) throw ...","typeGuard":"function isValidLivePreviewToken(t: unknown): t is string {\n  return typeof t === 'string' && t.split('.').length === 3 && (() => { try { JSON.parse(Buffer.from(t.split('.')[1], 'base64').toString()); return true; } catch { return false; } })();\n}","tryCatchPattern":"try {\n  watcher.setAuth(token);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Live-preview token is invalid') {\n    // prompt user / fail startup with guidance on copying the full JWT\n  } else throw e;\n}","preventionTips":["Paste the token as a single unquoted line; prefer env vars over manual input.","Validate the JWT shape (three dot-separated base64 segments) before calling setAuth.","Use the live-preview token type specifically — not a deploy or API token."],"tags":["jwt","live-preview","token","configuration"],"backgroundTag":"jwt-token-invalid","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}