clockworklabs/SpacetimeDB · error · anyhow::Error
Failed to request token
Error message
Failed to request token
What it means
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.
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
Example fix
# before (self-hosted server without web auth) spacetime login --server http://localhost:3000 # after spacetime login --server maincloud
Defensive patterns
Strategy: retry
Validate before calling
# Verify the host actually serves web auth before login:
curl -sS -o /dev/null -w '%{http_code}\n' -X POST "$HOST/api/auth/cli/login/request-token" \
| grep -q 200 || echo 'host does not serve web auth — use maincloud' Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Failed to get token
- Unknown error
- Response data is missing.
- Session token is missing in response.
- Login required to publish to maincloud server
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/9d6348284cc2cd36.
Report an issue: GitHub.
Appendix: source
Thrown at crates/cli/src/subcommands/login.rs:218
Ok(Some(WebLoginSessionResponseApproved {
session_token: session_token.clone(),
}))
}
}
async fn web_login(remote: &Url, open_browser: bool) -> Result<String, anyhow::Error> {
let client = reqwest::Client::new();
let response: WebLoginTokenResponse = client
.post(remote.join("/api/auth/cli/login/request-token")?)
.send()
.await?
.error_for_status()?
.json()
.await?;
if !response.success {
return Err(anyhow::anyhow!("Failed to request token"));
}
let web_login_request_token = response.data.token.as_str();
let mut browser_url = remote.join("login/cli")?;
browser_url
.query_pairs_mut()
.append_pair("token", web_login_request_token);
if open_browser {
println!("Opening {browser_url} in your browser.");
if webbrowser::open(browser_url.as_str()).is_err() {
println!("Unable to open your browser! Please open the URL above manually.");
}
} else {
println!("Open {browser_url} in your browser to finish logging in.");
}
println!("Waiting to hear response from the server...");View on GitHub (pinned to 6dee26c6ef)