{"record":{"id":"8b7b916970eca02a","repo":"clockworklabs/SpacetimeDB","slug":"no-web-session-token","errorCode":null,"errorMessage":"No web session token","messagePattern":"No web session token","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"crates/cli/src/subcommands/logout.rs","lineNumber":33,"sourceCode":"\npub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> {\n    // Check if already logged out.\n    if config.spacetimedb_token().is_none() && config.web_session_token().is_none() {\n        println!(\"You are not logged in.\");\n        return Ok(());\n    }\n\n    let host: &String = args.get_one(\"auth-host\").unwrap();\n    let host = Url::parse(host)?;\n\n    let _ = ensure_logged_out(&mut config, &host).await;\n\n    Ok(())\n}\n\nasync fn server_logout(config: &mut Config, host: &Url) -> Result<(), anyhow::Error> {\n    let Some(web_session_token) = config.web_session_token() else {\n        anyhow::bail!(\"No web session token\");\n    };\n    // Best-effort server-side session invalidation.\n    let client = reqwest::Client::builder().timeout(Duration::from_secs(5)).build()?;\n    client\n        .post(host.join(\"auth/cli/logout\")?)\n        .header(\"Authorization\", format!(\"Bearer {web_session_token}\"))\n        .send()\n        .await?;\n    Ok(())\n}\n\n/// Logs out the user from the specified auth server.\n/// Returns true if the user was logged out, false if they were not logged in.\npub async fn ensure_logged_out(config: &mut Config, host: &Url) -> bool {\n    let Some(token) = config.spacetimedb_token() else {\n        return false;\n    };\n    // Grab identity before clearing tokens.","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/cli/src/subcommands/logout.rs#L15-L51","documentation":"`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.","triggerScenarios":"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.","commonSituations":"Fresh machines or CI where only a server URL was configured; scripted logout as cleanup; stale config after manual file edits.","solutions":["If your goal is clearing local credentials, you can ignore this — logout still removes them","Run `spacetime login` first if you actually need server-side session revocation","Check `spacetime whoami`/`spacetime server list` to confirm what session state exists locally"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"use spacetimedb_cli::Config;\n\nlet config = Config::load()?;\nif config.web_session_token().is_some() {\n    server_logout(&mut config, &host).await?; // server-side revocation\n}\n// always clear local credentials afterwards regardless","typeGuard":"fn has_web_session(config: &Config) -> bool {\n    config.web_session_token().is_some()\n}","tryCatchPattern":"if let Err(e) = server_logout(&mut config, &host).await {\n    if e.to_string().contains(\"No web session token\") {\n        // nothing to revoke; proceed with local logout\n    } else {\n        return Err(e);\n    }\n}","preventionTips":["Check `spacetime whoami` before logout to know whether a web session exists","Treat logout as best-effort: local credential clearing is what matters"],"tags":["spacetime-logout","auth","session","cli"],"backgroundTag":"missing-session-token","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}