tonhowtf/omniget · error

X_LOGIN_REQUIRED

X_LOGIN_REQUIRED

Error message

X_LOGIN_REQUIRED

What it means

The X client's require_login guard fails when the client has no authenticated session (authed() is false), returning the sentinel error with code X_LOGIN_REQUIRED. GraphQL/REST POST entry points (gql_post, rest_post_form, post_json_raw) call it before issuing requests, so any endpoint requiring a logged-in account is blocked without cookies.

Solutions

  1. Complete the X login flow in the app to establish cookies, then retry.
  2. Re-authenticate — the stored session cookie likely expired.
  3. Check client.authed() before calling auth-required endpoints and route to login UI.
  4. If the operation is meant to be public, use a guest-capable call path instead of the auth-guarded one.

Example fix

// before
client.gql_post(op, &vars).await?; // panics into X_LOGIN_REQUIRED when logged out
// after
if !client.authed() {
    return Err(AppError::LoginRequired); // route user to X login flow
}
client.gql_post(op, &vars).await?;
Defensive patterns

Strategy: validation

Validate before calling

// before any authenticated call
if !client.authed() {
    navigator.go("/x-login");
    return;
}

Type guard

fn ensure_authed(c: &XClient) -> anyhow::Result<()> { c.require_login() }

Try / catch

match client.gql_post(op, &vars).await {
    Err(e) if e.to_string().contains("X_LOGIN_REQUIRED") => route_to_login(),
    other => other?,
}

Prevention

When it happens

Trigger: Calling any authenticated X operation (posting, following, authenticated GraphQL queries) when no login cookies/session have been established on the client.

Common situations: User never logged in via the app's X login flow; cookies expired or were cleared; app restarted and session was not persisted; using guest-only client for auth-required endpoints.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/b0167feaeba72997. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/x/client.rs:169

        self.cookie.as_deref()
    }

    fn ct0(&self) -> Option<String> {
        self.cookie.as_deref().and_then(|c| cookie_value(c, "ct0"))
    }

    pub fn authed(&self) -> bool {
        self.cookie
            .as_deref()
            .map(|c| cookie_value(c, "auth_token").is_some() && cookie_value(c, "ct0").is_some())
            .unwrap_or(false)
    }

    pub fn require_login(&self) -> anyhow::Result<()> {
        if self.authed() {
            Ok(())
        } else {
            Err(anyhow!(LOGIN_REQUIRED))
        }
    }

    /// Id numerico do usuario logado (cookie `twid=u%3D<id>`).
    pub fn user_id(&self) -> Option<String> {
        let raw = cookie_value(self.cookie.as_deref()?, "twid")?;
        let dec = urlencoding::decode(&raw)
            .map(|c| c.to_string())
            .unwrap_or(raw);
        let id = dec
            .trim()
            .trim_start_matches("u=")
            .trim_matches('"')
            .to_string();
        (!id.is_empty() && id.chars().all(|c| c.is_ascii_digit())).then_some(id)
    }

    async fn guest_token(&self, force: bool) -> anyhow::Result<String> {

View on GitHub (pinned to 8600b91f42)