{"record":{"id":"42af345782eb45e3","repo":"jackwener/OpenCLI","slug":"upwork-session-cookies-missing","errorCode":null,"errorMessage":"Upwork session cookies missing","messagePattern":"Upwork session cookies missing","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/upwork/auth.js","lineNumber":12,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasUpworkSessionCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://www.upwork.com' });\n  const names = new Set(cookies.map(c => c.name));\n  return names.has('master_access_token') || names.has('XSRF-TOKEN') && names.has('user_uid');\n}\n\nasync function verifyUpworkIdentity(page) {\n  if (!await hasUpworkSessionCookie(page)) {\n    throw new AuthRequiredError('upwork.com', 'Upwork session cookies missing');\n  }\n  await page.goto('https://www.upwork.com/nx/find-work/');\n  await page.wait(3);\n  const probe = await page.evaluate(`\n    (() => {\n      if (/\\\\/(ab|account-security\\\\/login|signup)\\\\//.test(location.pathname)) {\n        return { kind: 'auth', detail: 'Upwork redirected to login flow' };\n      }\n      const nuxt = (typeof window !== 'undefined' && window.__NUXT__) ? window.__NUXT__ : null;\n      const state = nuxt && (nuxt.state || (nuxt.data && nuxt.data[0]));\n      const user = state && (state.user || (state.auth && state.auth.user));\n      const profile = user && (user.profile || user);\n      if (!profile || !profile.id) {\n        return { kind: 'auth', detail: 'Upwork __NUXT__ has no profile id — anonymous' };\n      }\n      return {\n        ok: true,\n        user_id: String(profile.id || profile.uid || ''),","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/upwork/auth.js#L1-L30","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Open https://www.upwork.com in the connected browser and sign in, then re-run the command.","Run the library's site login flow for upwork.com (registerSiteAuthCommands provides an interactive login).","Confirm the CLI is attached to the browser profile you actually use for Upwork.","Check cookies manually (master_access_token or XSRF-TOKEN + user_uid) to confirm the session state before retrying."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const cookies = await page.cookies('https://www.upwork.com');\nconst names = new Set(cookies.map(c => c.name));\nconst hasSession = names.has('master_access_token') || (names.has('XSRF-TOKEN') && names.has('user_uid'));\nif (!hasSession) throw new Error('Log in to upwork.com first');","typeGuard":"function hasUpworkSessionCookie(cookies) {\n  const names = new Set(cookies.map(c => c.name));\n  return names.has('master_access_token') || (names.has('XSRF-TOKEN') && names.has('user_uid'));\n}","tryCatchPattern":"try {\n  await runUpworkCommand();\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    console.log('Open https://www.upwork.com in the connected browser and sign in, then retry.');\n  } else throw e;\n}","preventionTips":["Log in to Upwork in the same browser profile the CLI attaches to.","Re-check session cookies before batches of Upwork commands.","Avoid incognito/cleared-cookie profiles for automation.","Refresh the session periodically; Upwork sessions expire."],"tags":["auth","cookies","upwork"],"backgroundTag":"missing-session-cookies","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}