{"record":{"id":"ea1a6c3fef40a42a","repo":"jackwener/OpenCLI","slug":"ctrip-login-uid-cookie-missing-anonymous","errorCode":null,"errorMessage":"Ctrip login_uid cookie missing — anonymous","messagePattern":"Ctrip login_uid cookie missing — anonymous","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/ctrip/auth.js","lineNumber":12,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasCtripLoginUid(page) {\n  const cookies = await page.getCookies({ url: 'https://www.ctrip.com' });\n  const loginUid = cookies.find(c => c.name === 'login_uid');\n  return Boolean(loginUid && loginUid.value);\n}\n\nasync function verifyCtripIdentity(page) {\n  if (!await hasCtripLoginUid(page)) {\n    throw new AuthRequiredError('ctrip.com', 'Ctrip login_uid cookie missing — anonymous');\n  }\n  await page.goto('https://my.ctrip.com/myinfo/MyInfoIndex.aspx');\n  await page.wait(2);\n  const cookies = await page.getCookies({ url: 'https://www.ctrip.com' });\n  const cookieMap = Object.fromEntries(cookies.map(c => [c.name, c.value]));\n  const loginUid = cookieMap['login_uid'] || '';\n  if (!loginUid) {\n    throw new AuthRequiredError('ctrip.com', 'Ctrip login_uid cookie absent after navigation');\n  }\n  const aheadRaw = cookieMap['AHeadUserInfo'] || '';\n  const params = new URLSearchParams(aheadRaw);\n  const userNameRaw = params.get('UserName') || '';\n  let userName = '';\n  if (userNameRaw) {\n    try {\n      userName = decodeURIComponent(userNameRaw);\n    } catch {\n      userName = userNameRaw;","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/ctrip/auth.js#L1-L30","documentation":"verifyCtripIdentity first checks the browser session's cookies for a login_uid cookie on www.ctrip.com; if absent or empty it throws AuthRequiredError('ctrip.com', 'Ctrip login_uid cookie missing — anonymous'), meaning you are not logged in. The CLI's Ctrip commands use cookie-based auth, so an anonymous session cannot proceed.","triggerScenarios":"Running any Ctrip command or `ctrip login`/verify when the connected browser profile has never logged into ctrip.com, cookies were cleared, or the session uses a fresh headless profile with no cookies.","commonSituations":"Fresh machine/container with an empty browser profile; browser cookie purge or privacy mode; pointing the CLI at the wrong browser profile; session expired and Ctrip dropped the cookie.","solutions":["Run the site's login flow (`ctrip login`) and complete Ctrip login at https://passport.ctrip.com/user/login in the CLI-controlled browser.","Verify the CLI is attached to the browser profile you actually use and that it isn't an incognito/temporary profile.","Re-check with `ctrip whoami`/verify after logging in; ensure login_uid appears in cookies for www.ctrip.com.","Avoid clearing cookies between runs; use a persistent profile."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// check for a logged-in session before running Ctrip commands\nconst who = await opencli.ctrip.whoami().catch(() => null);\nif (!who) {\n  await opencli.ctrip.login(); // completes passport.ctrip.com login\n}","typeGuard":null,"tryCatchPattern":"try {\n  const data = await runCtripCommand();\n} catch (err) {\n  if (err.name === 'AuthRequiredError' && /login_uid cookie missing/i.test(err.message)) {\n    await opencli.ctrip.login(); // then retry\n  } else throw err;\n}","preventionTips":["Run `ctrip login` before scripted Ctrip usage and confirm with whoami/verify.","Use a persistent browser profile; never incognito or ephemeral containers.","Don't clear cookies between runs.","Point the CLI at the same browser profile you log in with."],"tags":["auth-required","cookies","not-logged-in","ctrip"],"backgroundTag":"missing-auth-cookie","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}