clockworklabs/SpacetimeDB · error · anyhow::Error
Failed to request token
Error message
Failed to request token
What it means
The first step of web login is POST /api/auth/cli/login/request-token. The request succeeded at the HTTP level but the body carried success=false, so the CLI cannot obtain the one-time token that the browser flow needs, and fails with the generic 'Failed to request token' (login.rs:218).
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 524b4487d9)
Solutions
- Verify the server URL, e.g. `spacetime login --server https://mainnet.spacetimedb.com`
- Update the CLI to the latest release so its login protocol matches the server
- If self-hosted, ensure the auth/web components are deployed and reachable
- Retry once to rule out a transient failure
Defensive patterns
Strategy: retry
Validate before calling
# confirm the host actually serves the web-login API before logging in curl -sf -o /dev/null "$SPACETIME_SERVER/api/auth/cli/login/request-token" -X POST \ || echo "warning: $SPACETIME_SERVER may not support web login" >&2
Try / catch
for i in 1 2; do spacetime login --server "$SPACETIME_SERVER" && break sleep 3 done
Prevention
- Point --server at a host that serves the web login API
- Update the CLI before reporting auth failures
- Pre-verify self-hosted auth endpoints with curl
When it happens
Trigger: `spacetime login` (optionally with --server <url>) where the auth server refuses token issuance, e.g. {"success": false}.
Common situations: Pointing --server at a self-hosted node that lacks the web-auth endpoints; a typo'd or proxied server URL; a server too old for the CLI's web login flow.
Related errors
- Unknown error
- Response data is missing.
- Session token is missing in response.
- Failed to get token: {}
- Error fetching public key for issuer {raw_issuer}
AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16).
Data as JSON: /api/errors/9d6348284cc2cd36.
Report an issue: GitHub.