cube-js/cube · error

not logged in: run `cube login`, or set CUBE_API_URL and CUB

Error message

not logged in: run `cube login`, or set CUBE_API_URL and CUBE_API_KEY (or pass --api-url/--token)

What it means

`api()` needs an API URL and token, resolved from flags, env vars (CUBE_API_URL/CUBE_API_KEY), or the logged-in default context. If none are available, the CLI is effectively unauthenticated and bails telling the user to log in or provide credentials.

Source

Thrown at rust/cube-cli/src/main.rs:102

        match (url, token) {
            (Some(url), Some(token)) => {
                // Enable auto-refresh only when using the context's own access
                // token and it has a refresh token saved alongside it.
                let refresh = if self.token.is_none() {
                    ctx.and_then(|(name, c)| {
                        c.refresh_token
                            .as_ref()
                            .map(|rt| (rt.clone(), name.to_string()))
                    })
                } else {
                    None
                };
                match refresh {
                    Some((rt, name)) => client::Client::with_refresh(&url, &token, &rt, Some(name)),
                    None => client::Client::new(&url, &token),
                }
            }
            _ => bail!(
                "not logged in: run `cube login`, or set CUBE_API_URL and CUBE_API_KEY \
                 (or pass --api-url/--token)"
            ),
        }
    }
}

#[derive(Subcommand)]
enum Command {
    /// Log in to Cube Cloud and save credentials
    Login(commands::login::Args),
    /// Remove saved credentials
    Logout(commands::logout::Args),
    /// Show the currently authenticated user
    Whoami(commands::whoami::Args),
    /// Manage saved contexts (tenants)
    Context(commands::context::Args),

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Run `cube login` to authenticate interactively
  2. Set both CUBE_API_URL and CUBE_API_KEY environment variables
  3. Pass --api-url and --token flags explicitly for one-off invocations

Example fix

// before
cube deployments list   # no credentials anywhere
// after
export CUBE_API_URL=https://my_CUBE.cloud
export CUBE_API_KEY=abc123
cube deployments list
Defensive patterns

Strategy: validation

Validate before calling

const haveEnv = !!process.env.CUBE_API_URL && !!process.env.CUBE_API_KEY;
const haveConfig = fs.existsSync(cliConfigPath);
if (!haveEnv && !haveConfig) {
  throw new Error("not logged in: run `cube login` or set CUBE_API_URL/CUBE_API_KEY");
}

Try / catch

try {
  run(`cube ${cmd}`);
} catch (e) {
  if (String(e).includes("not logged in")) {
    run("cube login"); run(`cube ${cmd}`);
  } else throw e;
}

Prevention

When it happens

Trigger: Running any remote command (`cube deployments list`, `cube validate`, etc.) before ever running `cube login`, in a fresh CI container with no config file, or with CUBE_API_URL set but CUBE_API_KEY missing.

Common situations: New machine setup; Docker/CI images without the CLI config mounted; env vars partially set (URL without token); expired/cleared credentials.

Related errors


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