jackwener/OpenCLI · error · AuthRequiredError

Upwork session cookies missing

Error message

Upwork session cookies missing

What it means

verifyUpworkIdentity checks the connected browser's cookies for an Upwork session (master_access_token, or XSRF-TOKEN plus user_uid). If none are present it throws AuthRequiredError, signaling the caller must log in to upwork.com in the connected browser before automated commands can run.

Source

Thrown at clis/upwork/auth.js:12

import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';

async function hasUpworkSessionCookie(page) {
  const cookies = await page.getCookies({ url: 'https://www.upwork.com' });
  const names = new Set(cookies.map(c => c.name));
  return names.has('master_access_token') || names.has('XSRF-TOKEN') && names.has('user_uid');
}

async function verifyUpworkIdentity(page) {
  if (!await hasUpworkSessionCookie(page)) {
    throw new AuthRequiredError('upwork.com', 'Upwork session cookies missing');
  }
  await page.goto('https://www.upwork.com/nx/find-work/');
  await page.wait(3);
  const probe = await page.evaluate(`
    (() => {
      if (/\\/(ab|account-security\\/login|signup)\\//.test(location.pathname)) {
        return { kind: 'auth', detail: 'Upwork redirected to login flow' };
      }
      const nuxt = (typeof window !== 'undefined' && window.__NUXT__) ? window.__NUXT__ : null;
      const state = nuxt && (nuxt.state || (nuxt.data && nuxt.data[0]));
      const user = state && (state.user || (state.auth && state.auth.user));
      const profile = user && (user.profile || user);
      if (!profile || !profile.id) {
        return { kind: 'auth', detail: 'Upwork __NUXT__ has no profile id — anonymous' };
      }
      return {
        ok: true,
        user_id: String(profile.id || profile.uid || ''),

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open https://www.upwork.com in the connected browser and sign in, then re-run the command.
  2. Run the library's site login flow for upwork.com (registerSiteAuthCommands provides an interactive login).
  3. Confirm the CLI is attached to the browser profile you actually use for Upwork.
  4. Check cookies manually (master_access_token or XSRF-TOKEN + user_uid) to confirm the session state before retrying.
Defensive patterns

Strategy: try-catch

Validate before calling

const cookies = await page.cookies('https://www.upwork.com');
const names = new Set(cookies.map(c => c.name));
const hasSession = names.has('master_access_token') || (names.has('XSRF-TOKEN') && names.has('user_uid'));
if (!hasSession) throw new Error('Log in to upwork.com first');

Type guard

function hasUpworkSessionCookie(cookies) {
  const names = new Set(cookies.map(c => c.name));
  return names.has('master_access_token') || (names.has('XSRF-TOKEN') && names.has('user_uid'));
}

Try / catch

try {
  await runUpworkCommand();
} catch (e) {
  if (e instanceof AuthRequiredError) {
    console.log('Open https://www.upwork.com in the connected browser and sign in, then retry.');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling any Upwork command that runs verifyUpworkIdentity while the connected browser has no upwork.com session cookies — user never logged in, cookies expired/were cleared, or the wrong browser profile is connected.

Common situations: Fresh automation environment with a clean cookie jar; Upwork session expired after inactivity; user cleared cookies or used incognito; pointing the CLI at a browser profile that never visits Upwork.

Related errors


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