{"record":{"id":"7001fbe374b7a36a","repo":"jackwener/OpenCLI","slug":"reuters-com","errorCode":null,"errorMessage":"reuters.com","messagePattern":"reuters\\.com","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/reuters/auth.js","lineNumber":41,"sourceCode":"          try {\n            const u = JSON.parse(localStorage.getItem(oidcKey) || '{}');\n            cuid = String(u?.profile?.cuid || u?.profile?.sub || '');\n          } catch {}\n        }\n        if (!cuid) {\n          const ajs = localStorage.getItem('ajs_user_id');\n          if (ajs && ajs !== 'null') cuid = ajs;\n        }\n        if (!cuid) {\n          return { kind: 'auth', detail: 'Reuters logged-in but cuid missing — session shape drifted' };\n        }\n        return { ok: true, user_id: cuid, subscribed: Boolean(subState.isSubscribed) };\n      } catch (e) {\n        return { kind: 'exception', detail: String(e && e.message || e) };\n      }\n    })()\n  `);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('reuters.com', probe.detail);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`Reuters whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Reuters probe: ${JSON.stringify(probe)}`);\n  return { user_id: probe.user_id, subscribed: probe.subscribed };\n}\n\nregisterSiteAuthCommands({\n  site: 'reuters',\n  domain: 'reuters.com',\n  loginUrl: 'https://www.reuters.com/account/sign-in/',\n  columns: ['user_id', 'subscribed'],\n  verify: verifyReutersIdentity,\n  // No-navigation poll: check localStorage on the current page so login-flow\n  // polling doesn't bounce the user off the sign-in page every interval.\n  poll: async (page) => {\n    const loggedIn = await page.evaluate(`(() => {\n      try {\n        const raw = localStorage.getItem('rcom-subscription-state');\n        return raw ? JSON.parse(raw).isLoggedIn === true : false;","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reuters/auth.js#L23-L59","documentation":"verifyReutersIdentity (the reuters whoami/identity verify step) throws AuthRequiredError for reuters.com when its in-page probe finds the localStorage key rcom-subscription-state missing or its isLoggedIn flag not true — i.e. there is no authenticated Reuters session in the browser.","triggerScenarios":"Running the reuters identity/whoami command with no prior login; a logged-out or expired session; localStorage cleared; the probe also fires when logged in but the cuid cannot be recovered (session shape drifted), reported via the probe detail.","commonSituations":"Forgetting to run `reuters auth login` before whoami; Reuters session expiring after inactivity; browser profile reset wiping localStorage; a Reuters frontend change renaming the localStorage keys, so a logged-in user still appears anonymous.","solutions":["Run the reuters auth login command and complete sign-in in the browser","Re-run whoami after login to confirm the session registers","If logged in but still failing with 'cuid missing', re-login to rebuild localStorage keys","Clear site data and log in fresh if the session state is stale"],"exampleFix":"// before\nreuters whoami   # AuthRequiredError: anonymous\n// after\nreuters auth login   # complete sign-in flow\nreuters whoami       # -> { user_id: \"cuid...\", subscribed: true }","handlingStrategy":"try-catch","validationCode":"// caller-side precheck (mirrors the probe)\nconst raw = localStorage.getItem('rcom-subscription-state');\nconst loggedIn = raw ? JSON.parse(raw).isLoggedIn === true : false;\nif (!loggedIn) throw new Error('reuters.com session required — run auth login first');","typeGuard":"function isReutersLoggedIn(raw) {\n  try { return JSON.parse(raw)?.isLoggedIn === true; } catch { return false; }\n}","tryCatchPattern":"try {\n  return await reutersWhoami();\n} catch (e) {\n  if (e instanceof AuthRequiredError || e.constructor.name === 'AuthRequiredError') {\n    await runSiteAuthLogin('reuters');\n    return await reutersWhoami();\n  }\n  throw e;\n}","preventionTips":["Always run the reuters login flow before identity/whoami commands","Detect AuthRequiredError and trigger login automatically in wrappers","Re-login when localStorage session keys expire or reset","Handle 'cuid missing' details by rebuilding the session with a fresh login"],"tags":["auth","session","login"],"backgroundTag":"auth-required-not-logged-in","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}