{"record":{"id":"b63d4e2b8d2436be","repo":"jackwener/OpenCLI","slug":"taobao-tracknick-cookie-missing-anonymous","errorCode":null,"errorMessage":"Taobao tracknick cookie missing — anonymous","messagePattern":"Taobao tracknick cookie missing — anonymous","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/taobao/auth.js","lineNumber":11,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasTaobaoSessionCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://www.taobao.com' });\n  return cookies.some(c => c.name === 'tracknick' && c.value);\n}\n\nasync function verifyTaobaoIdentity(page) {\n  if (!await hasTaobaoSessionCookie(page)) {\n    throw new AuthRequiredError('taobao.com', 'Taobao tracknick cookie missing — anonymous');\n  }\n  await page.goto('https://i.taobao.com/my_itaobao');\n  await page.wait(2);\n  const finalUrl = await page.evaluate(`location.href`);\n  if (/login\\.taobao\\.com\\/member\\/login/.test(String(finalUrl || ''))) {\n    throw new AuthRequiredError('taobao.com', `Taobao my_itaobao redirected to login: ${finalUrl}`);\n  }\n  const cookies = await page.getCookies({ url: 'https://www.taobao.com' });\n  const tracknick = cookies.find(c => c.name === 'tracknick')?.value || '';\n  if (!tracknick) {\n    throw new AuthRequiredError('taobao.com', 'Taobao tracknick cookie absent after navigation');\n  }\n  const domInfo = await page.evaluate(`\n    (() => {\n      const nick = (document.querySelector('.user-nick, .site-nav-user, .user-name')?.innerText || '').trim();\n      const html = document.body?.innerHTML || '';\n      const userIdMatch = html.match(/userId[\\\"'\\\\s:=]+(\\\\d+)/i);\n      return { nickname: nick, user_id: userIdMatch?.[1] || '' };","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/taobao/auth.js#L1-L29","documentation":"verifyTaobaoIdentity first checks the browser cookie jar for a non-empty `tracknick` cookie on www.taobao.com — Taobao's marker of an authenticated session. If absent, it throws AuthRequiredError ('taobao.com') because the session is anonymous and identity cannot be verified.","triggerScenarios":"page.getCookies({ url: 'https://www.taobao.com' }) contains no `tracknick` cookie with a value — never logged in on this profile, cookies expired/cleared, or the login flow never completed.","commonSituations":"Fresh automation profile; cookie expiry after Taobao's session TTL; user cleared cookies or used a different profile; corporate proxy blocking taobao.com cookie domains.","solutions":["Run `taobao auth login` and complete login so the tracknick cookie is set.","Confirm with `taobao auth status` that the quick check passes before running commands.","Re-login if cookies expired; Taobao sessions do not last indefinitely.","Ensure the CLI uses a persistent browser profile so cookies survive restarts."],"exampleFix":"// before: assuming a session exists\nconst identity = await verifyTaobaoIdentity(page);\n// after: pre-check and login when anonymous\nconst cookies = await page.getCookies({ url: 'https://www.taobao.com' });\nif (!cookies.some(c => c.name === 'tracknick' && c.value)) {\n  await taobaoLogin(page);\n}\nconst identity = await verifyTaobaoIdentity(page);","handlingStrategy":"validation","validationCode":"const cookies = await page.getCookies({ url: 'https://www.taobao.com' });\nif (!cookies.some(c => c.name === 'tracknick' && c.value)) {\n  await taobaoLogin(page); // establish session before proceeding\n}","typeGuard":"function hasTaobaoSession(cookies) {\n  return cookies.some(c => c.name === 'tracknick' && !!c.value);\n}","tryCatchPattern":"try {\n  const identity = await verifyTaobaoIdentity(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError && /tracknick cookie missing/.test(e.message)) {\n    await taobaoLogin(page);\n    return verifyTaobaoIdentity(page);\n  }\n  throw e;\n}","preventionTips":["Always run the auth quick-check before identity-dependent commands","Keep cookies in a persistent profile","Schedule re-login when sessions expire"],"tags":["auth","taobao","cookies","session-expired"],"backgroundTag":"missing-session-cookie","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}