{"record":{"id":"c87595fc582da03b","repo":"jackwener/OpenCLI","slug":"rednote-com","errorCode":null,"errorMessage":"rednote.com","messagePattern":"rednote\\.com","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/rednote/auth.js","lineNumber":11,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasRednoteSessionCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://www.rednote.com' });\n  return cookies.some(c => c.name === 'web_session' && c.value);\n}\n\nasync function verifyRednoteIdentity(page) {\n  if (!await hasRednoteSessionCookie(page)) {\n    throw new AuthRequiredError('rednote.com', 'Rednote web_session cookie missing');\n  }\n  await page.goto('https://www.rednote.com/explore');\n  await page.wait(2);\n  const probe = await page.evaluate(`\n    (() => {\n      const state = window.__INITIAL_STATE__;\n      if (!state?.user) {\n        return { kind: 'auth', detail: 'Rednote __INITIAL_STATE__.user missing' };\n      }\n      const loggedIn = state.user.loggedIn?._value;\n      const userInfo = state.user.userInfo?._value || {};\n      if (loggedIn !== true) {\n        return { kind: 'auth', detail: 'Rednote loggedIn._value=' + String(loggedIn) + ' — anonymous' };\n      }\n      const userId = String(userInfo.userId || userInfo.user_id || '');\n      const nickname = String(userInfo.nickname || userInfo.name || '');\n      if (!userId) {\n        return { kind: 'auth', detail: 'Rednote logged-in but userId missing — stale session' };","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rednote/auth.js#L1-L29","documentation":"This AuthRequiredError is thrown by verifyRednoteIdentity when hasRednoteSessionCookie finds no non-empty 'web_session' cookie for https://www.rednote.com in the browser context. The library uses this error to signal that the user is not logged in to rednote.com and must authenticate before site-specific commands can run. The first argument ('rednote.com') identifies the site requiring auth and the detail explains the missing cookie.","triggerScenarios":"Calling any rednote command that ends in verifyRednoteIdentity when the page's cookie jar for rednote.com lacks a web_session cookie, or has one with an empty value — i.e., never logged in, logged out, or cookies cleared/misscoped.","commonSituations":"Fresh browser profile with no prior rednote login; user logged out or session expired and Reddit-style cookie cleanup removed web_session; cookies cleared by privacy tooling or incognito mode; getCookies({ url }) scope mismatch so the cookie exists under a different domain/path than 'https://www.rednote.com'.","solutions":["Run the rednote login/registration flow (registerSiteAuthCommands provides it) to obtain a web_session cookie, then retry.","Open rednote.com in the automation browser and log in manually if using a persistent profile.","Check that cookies aren't being wiped between runs — use a persistent user data dir instead of a fresh incognito context.","Verify the cookie's domain: log in on www.rednote.com (not a regional mirror) so the cookie matches the 'https://www.rednote.com' URL scope used by getCookies.","Catch AuthRequiredError in caller code and trigger the login flow automatically before retrying the command."],"exampleFix":"// before: calling site commands directly and crashing\nawait rednoteCommand(page);\n\n// after: pre-check and authenticate when needed\nimport { AuthRequiredError } from './errors.js';\ntry {\n  await rednoteCommand(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError && e.site === 'rednote.com') {\n    await rednoteLogin(page);\n    await rednoteCommand(page);\n  } else throw e;\n}","handlingStrategy":"validation","validationCode":"const cookies = await page.getCookies({ url: 'https://www.rednote.com' });\nconst hasSession = cookies.some(c => c.name === 'web_session' && c.value);\nif (!hasSession) {\n  await rednoteLogin(page); // authenticate before running site commands\n}","typeGuard":"function hasRednoteSession(cookies) {\n  return Array.isArray(cookies) &&\n    cookies.some(c => c.name === 'web_session' && typeof c.value === 'string' && c.value.length > 0);\n}","tryCatchPattern":"try {\n  await rednoteCommand(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError && e.message.includes('rednote.com')) {\n    await rednoteLogin(page);\n    return rednoteCommand(page);\n  }\n  throw e;\n}","preventionTips":["Always run the login flow once before batch rednote operations.","Use a persistent browser profile so web_session survives between runs.","Log in on www.rednote.com specifically, matching the cookie URL scope.","Avoid incognito/ephemeral contexts or privacy extensions that strip cookies."],"tags":["auth","missing-cookie","rednote","session"],"backgroundTag":"missing-auth-cookie","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}