jackwener/OpenCLI · error · AuthRequiredError
Xiaoe admin page redirected to login: ${finalUrl}
Error message
Xiaoe admin page redirected to login: ${finalUrl} What it means
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.
Source
Thrown at clis/xiaoe/auth.js:17
import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';
async function hasXiaoeAdminCookie(page) {
const cookies = await page.getCookies({ url: 'https://admin.xiaoe-tech.com' });
return cookies.some(c => (c.name === 'XIAOEID' || c.name === 'b_user_token') && c.value);
}
async function verifyXiaoeIdentity(page) {
if (!await hasXiaoeAdminCookie(page)) {
throw new AuthRequiredError('xiaoe-tech.com', 'Xiaoe XIAOEID/b_user_token cookie missing — anonymous');
}
await page.goto('https://admin.xiaoe-tech.com/t/account/muti_index');
await page.wait(3);
const finalUrl = await page.evaluate(`location.href`);
if (/login|signin|#\/wx$/.test(String(finalUrl || ''))) {
throw new AuthRequiredError('xiaoe-tech.com', `Xiaoe admin page redirected to login: ${finalUrl}`);
}
const cookies = await page.getCookies({ url: 'https://admin.xiaoe-tech.com' });
const xiaoeId = cookies.find(c => c.name === 'XIAOEID')?.value || '';
const unionId = cookies.find(c => c.name === 'unionid')?.value || '';
const probe = await page.evaluate(`
(() => {
const bodyText = document.body?.innerText || '';
if (/微信扫码登录|手机号登录|登录小鹅通/.test(bodyText)) {
return { isLoginPage: true };
}
const nick = document.querySelector('.user-name, .nickname, [class*="userName"], [class*="user-info"]')?.innerText?.trim() || '';
return { isLoginPage: false, domNick: nick };
})()
`);
if (probe.isLoginPage) {
throw new AuthRequiredError('xiaoe-tech.com', 'Xiaoe admin page showed login UI — anonymous session');
}
const userId = xiaoeId || unionId;View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before
await verifyXiaoeIdentity(page);
// after
try {
await verifyXiaoeIdentity(page);
} catch (e) {
if (e instanceof AuthRequiredError) await runXiaoeLogin(page); // refresh session
else throw e;
} Defensive patterns
Strategy: retry
Validate before calling
await page.goto('https://admin.xiaoe-tech.com/t/account/muti_index');
const finalUrl = String(await page.evaluate('location.href'));
if (/login|signin|#\/wx$/.test(finalUrl)) await refreshXiaoeSession(); Type guard
function isLoginRedirect(url) {
return /login|signin|#\/wx$/.test(String(url || ''));
} Try / catch
try {
await verifyXiaoeIdentity(page);
} catch (e) {
if (e instanceof AuthRequiredError && /redirected to login/.test(e.message)) {
await runXiaoeLogin(page);
await verifyXiaoeIdentity(page);
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Taobao my_itaobao redirected to login: ${finalUrl}
- 请先在共享 Chrome 完成 1688 登录/验证,再重试(${action})
- Bilibili ${label} API requires login or permission: ${messag
- bilibili.com
- Boss redirected to login page
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/60c44e985ce4c7cb.
Report an issue: GitHub.