{"record":{"id":"249ccd17f5ea93a4","repo":"cube-js/cube","slug":"auth-isn-t-set-249ccd","errorCode":null,"errorMessage":"Auth isn't set","messagePattern":"Auth isn't set","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-backend-cloud/src/live-preview.ts","lineNumber":45,"sourceCode":"  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          ]\n        }\n      );\n\n      let preSaveTimeout: NodeJS.Timeout;\n      this.watcher.on('all', (/* event, p */) => {\n        if (preSaveTimeout) clearTimeout(preSaveTimeout);","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-backend-cloud/src/live-preview.ts#L27-L63","documentation":"LivePreviewWatcher.startWatch requires setAuth to have been called first; if this.auth is null it throws \"Auth isn't set\". The watcher cannot sync files to Cube Cloud without the deployment identity stored in the auth object.","triggerScenarios":"Calling startWatch() on a freshly constructed LivePreviewWatcher without calling setAuth(token) beforehand, or after setAuth failed earlier and left this.auth unset.","commonSituations":"Running the dev server in live-preview mode without providing the live-preview token; providing an invalid token (see 'Live-preview token is invalid') so auth never gets set; a code path that starts watching before authentication completes.","solutions":["Call setAuth(validLivePreviewJwt) before startWatch().","Ensure the live-preview token is supplied through your startup flow (env var/config) so the auth step runs before watching begins.","If setAuth throws, fix the token first — startWatch will keep failing until auth is successfully set.","Order your boot code: create watcher → setAuth → startWatch."],"exampleFix":"// before\nconst watcher = new LivePreviewWatcher();\nwatcher.startWatch(); // throws 'Auth isn't set'\n// after\nconst watcher = new LivePreviewWatcher();\nwatcher.setAuth(process.env.CUBE_LIVE_PREVIEW_TOKEN!);\nwatcher.startWatch();","handlingStrategy":"validation","validationCode":"if (!watcher['auth']) throw new Error('Call setAuth(token) before startWatch()');\n// or expose/check via a wrapper that tracks auth state","typeGuard":null,"tryCatchPattern":"try {\n  watcher.startWatch();\n} catch (e) {\n  if (e instanceof Error && e.message === \"Auth isn't set\") {\n    watcher.setAuth(process.env.CUBE_LIVE_PREVIEW_TOKEN!);\n    watcher.startWatch();\n  } else throw e;\n}","preventionTips":["Enforce boot order: construct watcher → setAuth → startWatch.","Guard startup code to require the live-preview token env var when live preview mode is enabled.","Handle setAuth failure explicitly so startWatch is never called in an unauthenticated state."],"tags":["auth","live-preview","configuration"],"backgroundTag":"missing-auth-credentials","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}