jackwener/OpenCLI · error · CliError

FETCH_ERROR

FETCH_ERROR

Error message

ONES login response missing user.uuid or user.token

What it means

After POSTing credentials to the ONES login endpoint, the CLI expects the JSON body to contain user.uuid and user.token. If either is missing it throws FETCH_ERROR, meaning authentication may have succeeded at the HTTP layer but the response schema differs from the documented Project API. Without uuid/token the CLI cannot build the Ones-User-Id/Ones-Auth-Token headers used by later calls.

Source

Thrown at clis/ones/login.js:57

            throw new CliError('CONFIG', 'Password required', 'Pass --password or set ONES_PASSWORD for non-interactive use.');
        }
        if (!email && !phone) {
            throw new CliError('CONFIG', 'email or phone required', 'Pass --email or --phone (or set ONES_EMAIL / ONES_PHONE).');
        }
        getOnesBaseUrl();
        const bodyObj = { password };
        if (email)
            bodyObj.email = email;
        else
            bodyObj.phone = phone;
        const parsed = (await onesFetchInPage(page, 'auth/login', {
            method: 'POST',
            body: JSON.stringify(bodyObj),
            auth: false,
        }));
        const user = parsed.user;
        if (!user?.uuid || !user?.token) {
            throw new CliError('FETCH_ERROR', 'ONES login response missing user.uuid or user.token', 'Your server build may differ from documented Project API.');
        }
        const uuid = String(user.uuid);
        const token = String(user.token);
        const name = String(user.name ?? '');
        const em = String(user.email ?? '');
        const base = getOnesBaseUrl();
        console.error([
            '',
            '后续请求会优先使用当前 Chrome 会话 Cookie;若接口仍要求 Header,可 export:',
            `  export ONES_BASE_URL=${JSON.stringify(base)}`,
            `  export ONES_USER_ID=${JSON.stringify(uuid)}`,
            `  export ONES_AUTH_TOKEN=${JSON.stringify(token)}`,
            '',
        ].join('\n'));
        return [
            {
                uuid,
                name,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify ONES_BASE_URL points at the correct ONES deployment origin (no proxy/SSO path).
  2. Print the raw response (verbose logging) to see what the server actually returned.
  3. Check your ONES server version against the documented Project API; if the schema changed, update the CLI or fall back to Cookie-based auth from a logged-in Chrome session.
  4. Use the browser-session auth path instead: log into ONES in Chrome and export ONES_USER_ID / ONES_AUTH_TOKEN manually if your build exposes them.

Example fix

// before: login against a proxied/SSO origin
ONES_BASE_URL=https://sso-gateway.corp.com opencli ones login ...
// after: hit the ONES deployment origin directly
ONES_BASE_URL=https://your-team.ones.cn opencli ones login --email me@corp.com --password '...'
Defensive patterns

Strategy: type-guard

Validate before calling

// after a manual login response, before using it
const user = parsed?.user;
if (!user?.uuid || !user?.token) {
  console.error('Login response lacks user.uuid/token — verify ONES_BASE_URL hits the real ONES API, not an SSO/proxy page.');
}

Type guard

function hasLoginUser(p) {
  const u = p?.user;
  return typeof u === 'object' && u !== null &&
    typeof u.uuid === 'string' && u.uuid.length > 0 &&
    typeof u.token === 'string' && u.token.length > 0;
}

Try / catch

try {
  const me = await opencli.ones.login({ email, password });
} catch (e) {
  if (e.code === 'FETCH_ERROR' && /missing user\.uuid/.test(e.message)) {
    console.error('Server build mismatch — fall back to Cookie auth from a logged-in Chrome session.');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `opencli ones login` where the server replies with a body whose `user` object lacks `uuid` or `token` — e.g. a deployment whose login endpoint returns a different envelope, an error body with HTTP 200, or a newer ONES build that changed the login response shape.

Common situations: Self-hosted ONES instances on versions that diverge from the documented Project API; reverse proxies or SSO gateways that intercept the login POST and return their own payload; wrong ONES_BASE_URL hitting an HTML page instead of the API.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/f67706fac989910c. Report an issue: GitHub.