{"record":{"id":"5d05f1e976792da7","repo":"jackwener/OpenCLI","slug":"tiktok-session-cookies-sessionid-sid-tt-uid-tt-m","errorCode":null,"errorMessage":"TikTok session cookies (sessionid/sid_tt/uid_tt) missing","messagePattern":"TikTok session cookies \\(sessionid/sid_tt/uid_tt\\) missing","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/tiktok/auth.js","lineNumber":12,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasTiktokSessionCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://www.tiktok.com' });\n  const names = new Set(cookies.map(c => c.name));\n  return names.has('sessionid') || names.has('sid_tt') || names.has('uid_tt');\n}\n\nasync function verifyTiktokIdentity(page) {\n  if (!await hasTiktokSessionCookie(page)) {\n    throw new AuthRequiredError('www.tiktok.com', 'TikTok session cookies (sessionid/sid_tt/uid_tt) missing');\n  }\n  await page.goto('https://www.tiktok.com/foryou');\n  await page.wait(2);\n  const info = await page.evaluate(`\n    (() => {\n      const raw = document.querySelector('script[id=\"__UNIVERSAL_DATA_FOR_REHYDRATION__\"]')?.textContent;\n      if (!raw) return null;\n      let data;\n      try { data = JSON.parse(raw); } catch { return null; }\n      const scope = data?.['__DEFAULT_SCOPE__'] || {};\n      const seen = new Set();\n      const stack = [scope];\n      while (stack.length) {\n        const node = stack.pop();\n        if (!node || typeof node !== 'object' || seen.has(node)) continue;\n        seen.add(node);\n        if (Array.isArray(node)) { stack.push(...node); continue; }\n        const u = node.user;","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/tiktok/auth.js#L1-L30","documentation":"`verifyTiktokIdentity` first checks the browser's cookies for any of the TikTok session cookies `sessionid`, `sid_tt`, or `uid_tt`. If none is present it throws AuthRequiredError, because TikTok identity verification (reading the rehydration data for sec_uid/username/nickname) is only possible for a logged-in session. The library requires authentication before it can confirm whose session the browser holds.","triggerScenarios":"Calling `tiktok auth verify` (or any flow invoking verifyTiktokIdentity) against a browser profile that was never logged in, was logged out, or whose cookies were cleared; also triggered when the cookie store cannot be read so the cookie list is empty.","commonSituations":"Fresh headless browser profile with no login; expired TikTok session cookies purged by the browser; pointing the CLI at the wrong Chrome profile directory; running in a container without the profile volume mounted.","solutions":["Run the `tiktok auth login` flow and complete the login in the opened browser window so session cookies are stored.","Verify you are using the intended browser profile/user-data-dir that contains the logged-in TikTok session.","Log into tiktok.com manually in the same profile and confirm the session persists, then retry verification.","Check cookie file access/permissions if the profile is logged in but cookies read as empty (e.g. missing volume mount)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// ensure a logged-in TikTok profile exists before verification\nconst cookies = await page.cookies('https://www.tiktok.com');\nconst names = new Set(cookies.map(c => c.name));\nif (!names.has('sessionid') && !names.has('sid_tt') && !names.has('uid_tt')) {\n  await runTiktokLoginFlow(); // or prompt the user to log in\n}","typeGuard":"function hasTiktokSession(cookies) {\n  const names = new Set(cookies.map(c => c.name));\n  return names.has('sessionid') || names.has('sid_tt') || names.has('uid_tt');\n}","tryCatchPattern":"import { AuthRequiredError } from '@jackwener/opencli/errors';\ntry {\n  return await tiktokAuth.verify(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await tiktokAuth.login(); // interactive login, then retry\n    return tiktokAuth.verify(page);\n  }\n  throw e;\n}","preventionTips":["Always run the login flow before verification on fresh profiles.","Mount/persist the correct user-data-dir so cookies survive container restarts.","Check cookie presence proactively (quickCheck) before deep verification.","Alert users to re-login when TikTok invalidates old sessions."],"tags":["tiktok","auth","cookies","session"],"backgroundTag":"auth-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}