{"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/524b4487d949b61a07d4f39c862d1290259dfd20/crates/cli/src/subcommands/login.rs#L200-L236","documentation":"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).","triggerScenarios":"`spacetime login` (optionally with --server <url>) where the auth server refuses token issuance, e.g. {\"success\": false}.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# confirm the host actually serves the web-login API before logging in\ncurl -sf -o /dev/null \"$SPACETIME_SERVER/api/auth/cli/login/request-token\" -X POST \\\n  || echo \"warning: $SPACETIME_SERVER may not support web login\" >&2","typeGuard":null,"tryCatchPattern":"for i in 1 2; do\n  spacetime login --server \"$SPACETIME_SERVER\" && break\n  sleep 3\ndone","preventionTips":["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"],"tags":["login","auth","token-request","network"],"backgroundTag":"auth-token-request-failed","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}