clockworklabs/SpacetimeDB · warning · anyhow::Error

No web session token

Error message

No web session token

What it means

`spacetime logout` first tries to revoke the server-side web session by POSTing to /auth/cli/logout with the Bearer token from local config. If no web session token is stored locally (never logged in through the web flow, or already logged out), this step bails. The CLI treats logout as best-effort — callers discard this error and still clear local credentials — so hitting it usually just means there was nothing to revoke.

Solutions

  1. If your goal is clearing local credentials, you can ignore this — logout still removes them
  2. Run `spacetime login` first if you actually need server-side session revocation
  3. Check `spacetime whoami`/`spacetime server list` to confirm what session state exists locally
Defensive patterns

Strategy: validation

Validate before calling

use spacetimedb_cli::Config;

let config = Config::load()?;
if config.web_session_token().is_some() {
    server_logout(&mut config, &host).await?; // server-side revocation
}
// always clear local credentials afterwards regardless

Type guard

fn has_web_session(config: &Config) -> bool {
    config.web_session_token().is_some()
}

Try / catch

if let Err(e) = server_logout(&mut config, &host).await {
    if e.to_string().contains("No web session token") {
        // nothing to revoke; proceed with local logout
    } else {
        return Err(e);
    }
}

Prevention

When it happens

Trigger: Running `spacetime logout` when `spacetime login` was never completed; logging out twice in a row; config file cleared/corrupted so web_session_token is absent.

Common situations: Fresh machines or CI where only a server URL was configured; scripted logout as cleanup; stale config after manual file edits.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20). Data as JSON: /api/errors/8b7b916970eca02a. Report an issue: GitHub.

Appendix: source

Thrown at crates/cli/src/subcommands/logout.rs:33

pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> {
    // Check if already logged out.
    if config.spacetimedb_token().is_none() && config.web_session_token().is_none() {
        println!("You are not logged in.");
        return Ok(());
    }

    let host: &String = args.get_one("auth-host").unwrap();
    let host = Url::parse(host)?;

    let _ = ensure_logged_out(&mut config, &host).await;

    Ok(())
}

async fn server_logout(config: &mut Config, host: &Url) -> Result<(), anyhow::Error> {
    let Some(web_session_token) = config.web_session_token() else {
        anyhow::bail!("No web session token");
    };
    // Best-effort server-side session invalidation.
    let client = reqwest::Client::builder().timeout(Duration::from_secs(5)).build()?;
    client
        .post(host.join("auth/cli/logout")?)
        .header("Authorization", format!("Bearer {web_session_token}"))
        .send()
        .await?;
    Ok(())
}

/// Logs out the user from the specified auth server.
/// Returns true if the user was logged out, false if they were not logged in.
pub async fn ensure_logged_out(config: &mut Config, host: &Url) -> bool {
    let Some(token) = config.spacetimedb_token() else {
        return false;
    };
    // Grab identity before clearing tokens.

View on GitHub (pinned to 6dee26c6ef)