{"record":{"id":"60c44e985ce4c7cb","repo":"jackwener/OpenCLI","slug":"xiaoe-admin-page-redirected-to-login-finalurl","errorCode":null,"errorMessage":"Xiaoe admin page redirected to login: ${finalUrl}","messagePattern":"Xiaoe admin page redirected to login: (.+?)","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/xiaoe/auth.js","lineNumber":17,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasXiaoeAdminCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://admin.xiaoe-tech.com' });\n  return cookies.some(c => (c.name === 'XIAOEID' || c.name === 'b_user_token') && c.value);\n}\n\nasync function verifyXiaoeIdentity(page) {\n  if (!await hasXiaoeAdminCookie(page)) {\n    throw new AuthRequiredError('xiaoe-tech.com', 'Xiaoe XIAOEID/b_user_token cookie missing — anonymous');\n  }\n  await page.goto('https://admin.xiaoe-tech.com/t/account/muti_index');\n  await page.wait(3);\n  const finalUrl = await page.evaluate(`location.href`);\n  if (/login|signin|#\\/wx$/.test(String(finalUrl || ''))) {\n    throw new AuthRequiredError('xiaoe-tech.com', `Xiaoe admin page redirected to login: ${finalUrl}`);\n  }\n  const cookies = await page.getCookies({ url: 'https://admin.xiaoe-tech.com' });\n  const xiaoeId = cookies.find(c => c.name === 'XIAOEID')?.value || '';\n  const unionId = cookies.find(c => c.name === 'unionid')?.value || '';\n  const probe = await page.evaluate(`\n    (() => {\n      const bodyText = document.body?.innerText || '';\n      if (/微信扫码登录|手机号登录|登录小鹅通/.test(bodyText)) {\n        return { isLoginPage: true };\n      }\n      const nick = document.querySelector('.user-name, .nickname, [class*=\"userName\"], [class*=\"user-info\"]')?.innerText?.trim() || '';\n      return { isLoginPage: false, domNick: nick };\n    })()\n  `);\n  if (probe.isLoginPage) {\n    throw new AuthRequiredError('xiaoe-tech.com', 'Xiaoe admin page showed login UI — anonymous session');\n  }\n  const userId = xiaoeId || unionId;","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaoe/auth.js#L1-L35","documentation":"After cookies are present, verifyXiaoeIdentity navigates to https://admin.xiaoe-tech.com/t/account/muti_index and inspects location.href. If the final URL matches /login|signin|#\\/wx$/ the server redirected to a login or WeChat-binding page, meaning the cookie session is not actually valid, so AuthRequiredError is thrown with the final URL in the message.","triggerScenarios":"Cookies XIAOEID/b_user_token exist but are expired or revoked; server-side session invalidation redirects the muti_index page to a login/signin route or the #/wx WeChat-login hash.","commonSituations":"Session expired overnight (Xiaoe admin sessions are short-lived); password changed elsewhere invalidating the token; Xiaoe forcing re-auth via WeChat scan; clock skew or stale cookies copied from another profile.","solutions":["Re-run the xiaoe login flow to refresh XIAOEID/b_user_token cookies, then retry.","Inspect the finalUrl in the message to see which login route the admin redirected to.","Clear stale admin.xiaoe-tech.com cookies and log in fresh.","If #/wx appears, complete the WeChat binding/scan the admin console demands."],"exampleFix":"// before\nawait verifyXiaoeIdentity(page);\n// after\ntry {\n  await verifyXiaoeIdentity(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError) await runXiaoeLogin(page); // refresh session\n  else throw e;\n}","handlingStrategy":"retry","validationCode":"await page.goto('https://admin.xiaoe-tech.com/t/account/muti_index');\nconst finalUrl = String(await page.evaluate('location.href'));\nif (/login|signin|#\\/wx$/.test(finalUrl)) await refreshXiaoeSession();","typeGuard":"function isLoginRedirect(url) {\n  return /login|signin|#\\/wx$/.test(String(url || ''));\n}","tryCatchPattern":"try {\n  await verifyXiaoeIdentity(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError && /redirected to login/.test(e.message)) {\n    await runXiaoeLogin(page);\n    await verifyXiaoeIdentity(page);\n  } else throw e;\n}","preventionTips":["Refresh the session proactively before long scraping jobs.","Detect login redirects early and re-auth instead of proceeding.","Log the final URL on auth failures to diagnose which route redirected."],"tags":["auth","session-expired","redirect","xiaoe"],"backgroundTag":"auth-session-expired","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}