{"record":{"id":"06a0bdc58f2caf66","repo":"jackwener/OpenCLI","slug":"xiaoe-admin-page-showed-login-ui-anonymous-sessi","errorCode":null,"errorMessage":"Xiaoe admin page showed login UI — anonymous session","messagePattern":"Xiaoe admin page showed login UI — anonymous session","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/xiaoe/auth.js","lineNumber":33,"sourceCode":"  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;\n  if (!userId) {\n    throw new CommandExecutionError('Xiaoe admin page rendered but no user_id cookie extractable — stale session');\n  }\n  return { user_id: String(userId), nickname: String(probe.domNick || '') };\n}\n\nregisterSiteAuthCommands({\n  site: 'xiaoe',\n  domain: 'xiaoe-tech.com',\n  loginUrl: 'https://admin.xiaoe-tech.com/',\n  columns: ['user_id', 'nickname'],\n  quickCheck: hasXiaoeAdminCookie,\n  verify: verifyXiaoeIdentity,\n  poll: async (page) => {\n    if (!await hasXiaoeAdminCookie(page)) {\n      throw new AuthRequiredError('xiaoe-tech.com', 'Waiting for Xiaoe XIAOEID/b_user_token cookie');","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaoe/auth.js#L15-L51","documentation":"The in-page probe script checks DOM markers of the login screen (login form elements or absence of any user-name/nickname element). If isLoginPage is true — the page rendered a login UI rather than the account page — the session is treated as anonymous and AuthRequiredError is thrown.","triggerScenarios":"The admin page at /t/account/muti_index renders but the injected probe finds login-page DOM (e.g. .login selectors) and no .user-name/.nickname/[class*=\"userName\"]/[class*=\"user-info\"] element.","commonSituations":"Xiaoe changed their admin DOM/class names so the authenticated page no longer matches the user-info selectors; SPA client-side redirect to a login view without changing the URL; partial render raced by the 3s wait.","solutions":["Log in again via the xiaoe login flow to establish a valid session.","Increase the wait/settle time after page.goto in case the SPA has not rendered the user info yet.","Check whether Xiaoe updated admin markup; update the probe selectors (.user-name, .nickname, etc.) if so.","Confirm in a real browser that muti_index shows the account page with the same cookies."],"exampleFix":"// before\nawait page.wait(3);\n// after\nawait page.goto('https://admin.xiaoe-tech.com/t/account/muti_index', { settleMs: 8000 }); // let SPA fully render before probing","handlingStrategy":"validation","validationCode":"const probe = await page.evaluate(`(() => ({ isLoginPage: !!document.querySelector('.login, [class*=\"login\"]') }))()`);\nif (probe.isLoginPage) throw new Error('login UI rendered — re-authenticate');","typeGuard":"function isAuthenticatedDom(probe) {\n  return probe && probe.isLoginPage === false;\n}","tryCatchPattern":"try {\n  await verifyXiaoeIdentity(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await page.wait(5); // allow SPA to finish rendering, then retry once\n    await verifyXiaoeIdentity(page);\n  } else throw e;\n}","preventionTips":["Allow generous settle time after navigation so the SPA renders user info before probing.","Re-auth on any login-UI detection instead of parsing further.","Watch for Xiaoe admin markup changes and update selectors."],"tags":["auth","dom-probe","spa","xiaoe"],"backgroundTag":"login-page-detected","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}