{"record":{"id":"7ca1566e162b1357","repo":"tonhowtf/omniget","slug":"cookie-twid-ausente-entre-de-novo-no-x","errorCode":null,"errorMessage":"cookie twid ausente: entre de novo no X","messagePattern":"cookie twid ausente: entre de novo no X","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/x/follows.rs","lineNumber":79,"sourceCode":"        .ok()\n        .and_then(|s| serde_json::from_str(&s).ok())\n        .unwrap_or_default();\n    log.get(&today()).copied().unwrap_or(0)\n}\n\nfn bump_today() {\n    let mut log: std::collections::HashMap<String, usize> = std::fs::read_to_string(log_path())\n        .ok()\n        .and_then(|s| serde_json::from_str(&s).ok())\n        .unwrap_or_default();\n    *log.entry(today()).or_default() += 1;\n    let _ = std::fs::write(log_path(), serde_json::to_string(&log).unwrap_or_default());\n}\n\npub async fn me(client: &XClient) -> anyhow::Result<XUser> {\n    let uid = client\n        .user_id()\n        .ok_or_else(|| anyhow!(\"cookie twid ausente: entre de novo no X\"))?;\n    let v = client\n        .gql_get(\n            \"UserByRestId\",\n            json!({ \"userId\": uid, \"withSafetyModeUserFields\": true }),\n            json!({ \"hidden_profile_likes_enabled\": true, \"subscriptions_verification_info_is_identity_verified_enabled\": false, \"responsive_web_twitter_article_notes_tab_enabled\": false, \"subscriptions_feature_can_gift_premium\": false, \"profile_label_improvements_pcf_label_in_post_enabled\": false }),\n            None,\n        )\n        .await?;\n    v.pointer(\"/data/user/result\")\n        .and_then(super::parse::parse_user)\n        .ok_or_else(|| anyhow!(\"nao consegui ler o perfil da sessao\"))\n}\n\nasync fn list(\n    client: &XClient,\n    op: &str,\n    uid: &str,\n    limit: usize,","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/x/follows.rs#L61-L97","documentation":"follows::me needs the authenticated user's numeric id, taken from the XClient's stored cookies (the `twid` cookie carries u=<id>). If user_id() returns None the client has no twid cookie, so it cannot issue the UserByRestId lookup and reports that the user must log in to X again.","triggerScenarios":"Calling follows::me (directly or via audit) with an XClient constructed without cookies, with a cookie jar missing the twid entry (guest session or partial login), or after cookies were cleared/corrupted on disk.","commonSituations":"Fresh install before any X login; login flow captured auth_token/ct0 but not twid; user cleared cookies in the browser and re-imported a partial jar; running in guest mode where twid is never set.","solutions":["Log in to X again so a complete cookie set including twid is captured and stored","Check authed()/user_id() before calling follows::me and route to the login flow instead","Verify the cookie storage file was not truncated (re-import all cookies from the browser session)","Confirm the twid cookie value parses as u=<id>; fix malformed imports"],"exampleFix":"// before\nlet user = follows::me(&client).await?;\n// after\nif client.user_id().is_none() {\n    prompt_relogin()?; // captures twid cookie\n}\nlet user = follows::me(&client).await?;","handlingStrategy":"validation","validationCode":"// Rust: guard before calling follows::me\nif client.user_id().is_none() {\n    return Err(anyhow!(\"twid cookie missing — log in to X first\"));\n}","typeGuard":"// Rust: narrowing helper\nfn has_session(client: &XClient) -> bool {\n    client.authed() && client.user_id().is_some()\n}","tryCatchPattern":"match follows::me(&client).await {\n    Err(e) if e.to_string().contains(\"twid ausente\") => {\n        relogin()?; // capture full cookie set incl. twid\n        follows::me(&client).await\n    }\n    r => r,\n}","preventionTips":["Check client.user_id() before any per-user API call","Ensure the login flow persists all cookies (twid, auth_token, ct0), not just auth ones","Detect partial cookie jars at load time and force re-login","Never run user-scoped audits in guest mode"],"tags":["x","cookies","authentication","missing-credential"],"backgroundTag":"authentication-required","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}