cube-js/cube · error

Auth isn't set

Error message

Auth isn't set

What it means

CubeCloudClient.request requires an AuthObject (from this.auth or the per-call auth option) before calling Cube Cloud; if neither is present it throws "Auth isn't set". The client was constructed without cloud credentials, so no authenticated API call can be made.

Source

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

  };
}

export class CubeCloudClient {
  public constructor(
    protected readonly auth?: AuthObject,
    protected readonly livePreview?: boolean
  ) {
  }

  private async request<T>(options: {
    url: (deploymentId: string) => string,
    auth?: AuthObject,
  } & RequestInit): Promise<T> {
    const { url, auth, ...restOptions } = options;

    const authorization = auth || this.auth;
    if (!authorization) {
      throw new Error('Auth isn\'t set');
    }
    // Ensure headers object exists in restOptions
    restOptions.headers = restOptions.headers || {};
    // Add authorization to headers
    (restOptions.headers as any).authorization = authorization.auth;
    (restOptions.headers as any)['Content-type'] = 'application/json';

    const response = await fetch(
      `${authorization.url}/${url(authorization.deploymentId || '')}`,
      restOptions,
    );

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

    return await response.json() as Promise<T>;
  }

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Provide the Cube Cloud auth token — construct CubeCloudClient with an AuthObject or pass { auth } to the call.
  2. For CLI deploys, ensure the cloud token is configured (cubejs cloud token / environment variable) before running the command.
  3. For live preview, ensure setAuth(token) is called on LivePreviewWatcher before anything triggers cloud requests.
  4. Verify the token is valid — getDeploymentToken should be used first to exchange an auth token for a JWT AuthObject.

Example fix

// before
const client = new CubeCloudClient();
await client.getDeploymentsList(); // throws 'Auth isn't set'
// after
const jwt = await client.getDeploymentToken(process.env.CUBE_CLOUD_DEPLOY_AUTH!);
const client2 = new CubeCloudClient({ auth: jwt, url: process.env.CUBE_CLOUD_HOST });
await client2.getDeploymentsList();
Defensive patterns

Strategy: validation

Validate before calling

function assertAuth(auth?: AuthObject | null): asserts auth is AuthObject {
  if (!auth || !auth.auth) throw new Error('Cube Cloud auth token required before calling the cloud API');
}
// usage
assertAuth(client['auth'] as AuthObject | undefined);

Type guard

function isAuthSet(auth: AuthObject | null | undefined): auth is AuthObject {
  return !!auth && typeof auth.auth === 'string' && auth.auth.length > 0;
}

Try / catch

try {
  await client.getDeploymentsList();
} catch (e) {
  if (e instanceof Error && e.message === "Auth isn't set") {
    // re-authenticate then retry
  } else throw e;
}

Prevention

When it happens

Trigger: Calling getDeploymentsList, getUpstreamHashes, startUpload, uploadFile, finishUpload, or setEnvVars on a CubeCloudClient created without an AuthObject and without passing { auth } to the call.

Common situations: Running `cubejs deploy` or related CLI commands without a Cube Cloud auth token configured; token file/env var missing (e.g. CUBE_CLOUD_DEPLOY_AUTH not set); LivePreviewWatcher.setAuth never called before operations that hit the cloud client.

Related errors


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