jackwener/OpenCLI · error · AuthRequiredError

Taobao my_itaobao redirected to login: ${finalUrl}

Error message

Taobao my_itaobao redirected to login: ${finalUrl}

What it means

After the tracknick cookie check, verifyTaobaoIdentity navigates to https://i.taobao.com/my_itaobao and reads the final URL. If it matches login.taobao.com/member/login, Taobao redirected the account page to login, proving the session is invalid despite the cookie — AuthRequiredError is thrown with the redirect URL.

Source

Thrown at clis/taobao/auth.js:17

import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';

async function hasTaobaoSessionCookie(page) {
  const cookies = await page.getCookies({ url: 'https://www.taobao.com' });
  return cookies.some(c => c.name === 'tracknick' && c.value);
}

async function verifyTaobaoIdentity(page) {
  if (!await hasTaobaoSessionCookie(page)) {
    throw new AuthRequiredError('taobao.com', 'Taobao tracknick cookie missing — anonymous');
  }
  await page.goto('https://i.taobao.com/my_itaobao');
  await page.wait(2);
  const finalUrl = await page.evaluate(`location.href`);
  if (/login\.taobao\.com\/member\/login/.test(String(finalUrl || ''))) {
    throw new AuthRequiredError('taobao.com', `Taobao my_itaobao redirected to login: ${finalUrl}`);
  }
  const cookies = await page.getCookies({ url: 'https://www.taobao.com' });
  const tracknick = cookies.find(c => c.name === 'tracknick')?.value || '';
  if (!tracknick) {
    throw new AuthRequiredError('taobao.com', 'Taobao tracknick cookie absent after navigation');
  }
  const domInfo = await page.evaluate(`
    (() => {
      const nick = (document.querySelector('.user-nick, .site-nav-user, .user-name')?.innerText || '').trim();
      const html = document.body?.innerHTML || '';
      const userIdMatch = html.match(/userId[\"'\\s:=]+(\\d+)/i);
      return { nickname: nick, user_id: userIdMatch?.[1] || '' };
    })()
  `);
  let decodedTracknick = '';
  try {
    decodedTracknick = JSON.parse('"' + tracknick.replace(/\\/g, '\\\\') + '"');
  } catch {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run `taobao auth login` again to establish a fresh, server-validated session.
  2. Clear taobao.com cookies first, then log in, to remove the stale tracknick.
  3. Retry; if the redirect persists immediately after login, complete any security verification Taobao presents in the browser.
  4. Avoid sharing one account across many automation sessions, which triggers risk-control logouts.

Example fix

// before: trusting cookie presence only
if (cookies.some(c => c.name === 'tracknick')) return identity;
// after: treat login redirect as auth failure and re-authenticate
try {
  return await verifyTaobaoIdentity(page);
} catch (e) {
  if (e instanceof AuthRequiredError && /redirected to login/.test(e.message)) {
    await clearTaobaoCookies(page);
    await taobaoLogin(page);
    return verifyTaobaoIdentity(page);
  }
  throw e;
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const identity = await verifyTaobaoIdentity(page);
} catch (e) {
  if (e instanceof AuthRequiredError && /redirected to login/.test(e.message)) {
    // stale cookie accepted locally but rejected server-side: clear and re-login
    await clearTaobaoCookies(page);
    await taobaoLogin(page);
    return verifyTaobaoIdentity(page);
  }
  throw e;
}

Prevention

When it happens

Trigger: Navigating to i.taobao.com/my_itaobao lands on login.taobao.com/member/login — a stale/half-valid tracknick cookie that Taobao server-side rejects, an expired session not yet cookie-cleared, or a security re-verification requirement.

Common situations: Expired-but-present session cookie (cookie survives logout server-side); Taobao risk control forcing re-auth; logged in on another device invalidating this session; nick/account changes requiring re-verification.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/f127c2cfcba3e1b5. Report an issue: GitHub.