{"record":{"id":"9d6348284cc2cd36","repo":"clockworklabs/SpacetimeDB","slug":"failed-to-request-token","errorCode":null,"errorMessage":"Failed to request token","messagePattern":"Failed to request token","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/login.rs","lineNumber":218,"sourceCode":"        Ok(Some(WebLoginSessionResponseApproved {\n            session_token: session_token.clone(),\n        }))\n    }\n}\n\nasync fn web_login(remote: &Url, open_browser: bool) -> Result<String, anyhow::Error> {\n    let client = reqwest::Client::new();\n\n    let response: WebLoginTokenResponse = client\n        .post(remote.join(\"/api/auth/cli/login/request-token\")?)\n        .send()\n        .await?\n        .error_for_status()?\n        .json()\n        .await?;\n\n    if !response.success {\n        return Err(anyhow::anyhow!(\"Failed to request token\"));\n    }\n\n    let web_login_request_token = response.data.token.as_str();\n\n    let mut browser_url = remote.join(\"login/cli\")?;\n    browser_url\n        .query_pairs_mut()\n        .append_pair(\"token\", web_login_request_token);\n    if open_browser {\n        println!(\"Opening {browser_url} in your browser.\");\n        if webbrowser::open(browser_url.as_str()).is_err() {\n            println!(\"Unable to open your browser! Please open the URL above manually.\");\n        }\n    } else {\n        println!(\"Open {browser_url} in your browser to finish logging in.\");\n    }\n\n    println!(\"Waiting to hear response from the server...\");","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/cli/src/subcommands/login.rs#L200-L236","documentation":"First network step of `spacetime login` web flow: the CLI POSTs to /api/auth/cli/login/request-token. Transport or HTTP-level failures already propagate as reqwest errors; this specific error fires when the request succeeded (HTTP OK, JSON parsed) but the body says success: false — the server refused to mint a login request token, and the response carries no machine-readable reason for this stage.","triggerScenarios":"The auth endpoint responds 200 with {success: false} (or missing/empty token data that leads success check to fail). Typical server-side causes: auth service degraded, rate-limiting login token issuance, or CLI pointing at a server whose auth routes are misconfigured (e.g. wrong --server host with a web frontend that always 200s).","commonSituations":"Logging in against a self-hosted/standalone server that does not run the web auth endpoints; maincloud auth incidents or rate limits; DNS/hosts entries pointing the server name at a CDN that returns a JSON 200 error page.","solutions":["Retry after a short wait (rate limits and transient auth-service issues are the most common cause)","Verify you are logging in to a host that actually provides web auth: `spacetime login --server maincloud` for the managed cloud","For self-hosted servers, check that the web/auth endpoints are deployed and healthy, and that your CLI version matches the server version"],"exampleFix":"# before (self-hosted server without web auth)\nspacetime login --server http://localhost:3000\n# after\nspacetime login --server maincloud","handlingStrategy":"retry","validationCode":"# Verify the host actually serves web auth before login:\ncurl -sS -o /dev/null -w '%{http_code}\\n' -X POST \"$HOST/api/auth/cli/login/request-token\" \\\n  | grep -q 200 || echo 'host does not serve web auth — use maincloud'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use `--server maincloud` for web login; not every self-hosted server runs the auth endpoints","Retry once after a short delay — issuance can be rate-limited","Pin the correct server host in config before scripting logins"],"tags":["cli","login","auth","web-login","api-error","network"],"backgroundTag":"auth-token-request-failed","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"}