{"record":{"id":"867a3a898d7c4029","repo":"jackwener/OpenCLI","slug":"chaoxing-session-cookies-missing","errorCode":null,"errorMessage":"Chaoxing session cookies missing","messagePattern":"Chaoxing session cookies missing","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/chaoxing/auth.js","lineNumber":11,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasChaoxingSessionCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://i.chaoxing.com' });\n  return cookies.some(c => /^(UID|_uid|chaoxinguser|cx_p_token)$/i.test(c.name) && c.value);\n}\n\nasync function verifyChaoxingIdentity(page) {\n  if (!await hasChaoxingSessionCookie(page)) {\n    throw new AuthRequiredError('chaoxing.com', 'Chaoxing session cookies missing');\n  }\n  await page.goto('https://i.chaoxing.com/');\n  await page.wait(3);\n  const probe = await page.evaluate(`\n    (() => {\n      if (/passport2\\\\.chaoxing\\\\.com\\\\/login/.test(location.href)) {\n        return { kind: 'auth', detail: 'Chaoxing i.chaoxing.com redirected to passport2 login' };\n      }\n      const userIdCookie = (document.cookie.split('; ').find(c => /^(_uid|UID)=/.test(c)) || '').split('=')[1] || '';\n      let userName = '';\n      const unameCookie = (document.cookie.split('; ').find(c => /^uname=/.test(c)) || '').split('=')[1] || '';\n      if (unameCookie) {\n        try { userName = decodeURIComponent(unameCookie); } catch { userName = unameCookie; }\n      }\n      if (!userName) {\n        const el = document.querySelector('.userTitle, .myInfo, .user-name, [class*=userName]');\n        userName = (el?.innerText || '').trim();\n      }","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/chaoxing/auth.js#L1-L29","documentation":"verifyChaoxingIdentity first checks the browser page's cookies for a non-empty UID, _uid, chaoxinguser, or cx_p_token cookie on i.chaoxing.com. If none exists it throws AuthRequiredError('chaoxing.com','Chaoxing session cookies missing') — the page is not logged into Chaoxing, so identity verification cannot proceed.","triggerScenarios":"Calling the chaoxing auth/whoami command with a fresh or logged-out Playwright page; cookies cleared by browser context reset; login previously failed silently so no identity cookie was ever set.","commonSituations":"Running commands before ever logging in; browser context recreated without restoring saved cookies; Chaoxing logged the account out server-side and cleared cookies.","solutions":["Run the chaoxing login command to establish a session, then retry","Persist and reload cookies between runs (storageState) so the session survives restarts","Verify with page.getCookies that at least one of UID/_uid/chaoxinguser/cx_p_token is present and non-empty","Check that the login flow actually completed (no captcha/SSO redirect left pending)"],"exampleFix":"// before\nawait verifyChaoxingIdentity(page);\n// after\nconst cookies = await page.getCookies({ url: 'https://i.chaoxing.com' });\nif (!cookies.some(c => /^(UID|_uid|cx_p_token)$/i.test(c.name))) {\n  await chaoxingLogin(page); // establish session first\n}\nawait verifyChaoxingIdentity(page);","handlingStrategy":"try-catch","validationCode":"const cookies = await page.getCookies({ url: 'https://i.chaoxing.com' });\nconst loggedIn = cookies.some(c => /^(UID|_uid|chaoxinguser|cx_p_token)$/i.test(c.name) && c.value);\nif (!loggedIn) await chaoxingLogin(page);","typeGuard":"function hasSessionCookie(cs) { return cs.some(c => /^(UID|_uid|chaoxinguser|cx_p_token)$/i.test(c.name) && c.value); }","tryCatchPattern":"try { const identity = await whoami(page); }\ncatch (e) { if (e instanceof AuthRequiredError && e.message.includes('cookies missing')) { await login(page); return whoami(page); } throw e; }","preventionTips":["Always run login before identity commands on a fresh browser context","Save/restore storageState so cookies persist between invocations","Verify cookie names UID/_uid/cx_p_token are present after login","Re-login after any Chaoxing password change or server-side logout"],"tags":["chaoxing","auth","cookies","session"],"backgroundTag":"auth-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}