cube-js/cube · error

JWT token is not present in the response

Error message

JWT token is not present in the response

What it means

After a successful (ok) response from the /v1/token endpoint, getDeploymentToken parses the JSON and requires a jwt field; if the body lacks it, it throws this error. It means Cube Cloud accepted the request but returned an unexpected payload — the token exchange did not produce a usable JWT.

Source

Thrown at packages/cubejs-backend-cloud/src/cloud.ts:84

  public async getDeploymentToken(authToken: string) {
    const response = await fetch(
      `${process.env.CUBE_CLOUD_HOST || 'https://cubecloud.dev'}/v1/token`,
      {
        method: 'POST',
        headers: { 'Content-type': 'application/json' },
        body: JSON.stringify({ token: authToken })
      }
    );

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    const res = await response.json() as any;

    if (!res.jwt) {
      throw new Error('JWT token is not present in the response');
    }

    return res.jwt;
  }

  private extendRequestByLivePreview() {
    return this.livePreview ? '?live=true' : '';
  }

  public getUpstreamHashes({ auth }: { auth?: AuthObject } = {}): Promise<UpstreamHashesResponse> {
    return this.request({
      url: (deploymentId: string) => `build/deploy/${deploymentId}/files${this.extendRequestByLivePreview()}`,
      method: 'GET',
      auth,
    });
  }

  public startUpload({ auth }: { auth?: AuthObject } = {}): Promise<StartUploadResponse> {

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Log/inspect the raw response body from /v1/token to see what was actually returned.
  2. Regenerate the auth token and retry the exchange.
  3. Verify CUBE_CLOUD_HOST points at the genuine Cube Cloud API (not a proxy or wrong service).
  4. If the API contract changed, upgrade @cubejs-backend-cloud to the latest version.

Example fix

// before
const res = await response.json() as any;
return res.jwt; // may be undefined
// after
const res = await response.json() as any;
if (!res?.jwt) throw new Error(`Token endpoint returned no jwt: ${JSON.stringify(res).slice(0, 200)}`);
return res.jwt;
Defensive patterns

Strategy: type-guard

Type guard

function hasJwt(res: unknown): res is { jwt: string } {
  return typeof res === 'object' && res !== null && 'jwt' in res && typeof (res as any).jwt === 'string' && (res as any).jwt.length > 0;
}
// usage: if (!hasJwt(await response.json())) throw new Error('unexpected /v1/token response');

Try / catch

try {
  const jwt = await client.getDeploymentToken(token);
} catch (e) {
  if (e instanceof Error && e.message === 'JWT token is not present in the response') {
    // log raw response body; check CUBE_CLOUD_HOST and API version
  } else throw e;
}

Prevention

When it happens

Trigger: The /v1/token endpoint returns 2xx with a JSON body that has no jwt property — e.g. an API contract change on the Cube Cloud side, an error JSON body returned with 2xx status, or a proxy/gateway returning a 2xx HTML/empty body.

Common situations: Intercepting proxies or captive portals returning 200 with non-expected content; Cube Cloud API version drift; using a token type that the endpoint accepts silently but doesn't issue a JWT for.

Related errors


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/ed7a7f840f3e708f. Report an issue: GitHub.