jackwener/OpenCLI · error · AuthRequiredError
Ke lianjia_token cookie missing — anonymous
Error message
Ke lianjia_token cookie missing — anonymous
What it means
verifyKeIdentity checks the browser session for a non-empty `lianjia_token` cookie on ke.com before probing the DOM. If the cookie is absent it throws AuthRequiredError meaning the browser is anonymous — the user must log into ke.com in the managed browser session before CLI commands can authenticate.
Source
Thrown at clis/ke/auth.js:11
import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';
async function hasKeSessionCookie(page) {
const cookies = await page.getCookies({ url: 'https://www.ke.com' });
return cookies.some(c => c.name === 'lianjia_token' && c.value);
}
async function verifyKeIdentity(page) {
if (!await hasKeSessionCookie(page)) {
throw new AuthRequiredError('ke.com', 'Ke lianjia_token cookie missing — anonymous');
}
await page.goto('https://www.ke.com/');
await page.wait(2);
const probe = await page.evaluate(`
(() => {
const loginBtn = document.querySelector('.btn-login, a[class*=actLoginBtn], .login-btn');
if (loginBtn && /登录|登陆/.test(loginBtn.innerText || '')) {
return { kind: 'auth', detail: 'Ke shows 登录 button — anonymous session' };
}
// 2026-08 贝壳新版 SSR:用户名在 .typeShowUser(脱敏手机号如 15****93),
// 旧锚点 .userNick/.user-name/.myInfo 已下线,故把 .typeShowUser 提到最前。
const el = document.querySelector('.typeShowUser a span, .typeShowUser a, .userNick, .user-name, .myInfo a, [class*=userNick]');
const username = (el?.innerText || '').trim();
if (!username) {
return { kind: 'auth', detail: 'Ke no user-name DOM anchor — anonymous or SSR failed' };
}
return { ok: true, username };
})()View on GitHub (pinned to 49907e53dc)
Solutions
- Run the site's login command to open https://clogin.ke.com/login/?service=https%3A%2F%2Fwww.ke.com and complete login in the browser
- Verify the cookie exists: in the browser devtools check www.ke.com cookies for `lianjia_token`
- Re-run verify after login; if it still fails, clear stale cookies and log in again
Example fix
// before (CLI) $ opencli ke house list # AuthRequiredError: lianjia_token missing // after $ opencli ke auth login # complete login in browser, then retry
Defensive patterns
Strategy: try-catch
Validate before calling
const cookies = await page.getCookies({ url: 'https://www.ke.com' });
const hasSession = cookies.some(c => c.name === 'lianjia_token' && c.value);
if (!hasSession) {
console.log('Not logged into ke.com — run `opencli ke auth login` first');
process.exit(2);
} Try / catch
import { AuthRequiredError } from '@jackwener/opencli/errors';
try {
await keCommand(args);
} catch (e) {
if (e instanceof AuthRequiredError) {
console.error('ke.com login required. Run: opencli ke auth login');
process.exitCode = 2;
} else throw e;
} Prevention
- Run `ke auth verify` before long batch jobs
- Persist a dedicated browser profile so cookies survive restarts
- Check cookie expiry and re-login proactively on a schedule
- Catch AuthRequiredError uniformly across site commands and print the login hint
When it happens
Trigger: Calling any `ke` site command (or `ke auth verify`) when the browser profile has never logged into ke.com; cookies were cleared; the session cookie expired and was dropped; page.getCookies returns no matching `lianjia_token` cookie.
Common situations: Fresh browser profile / new machine; user logged out in the shared browser; incognito context without persisted cookies; Lianjia/Beike invalidated old tokens server-side.
Related errors
- Could not detect a logged-in GitHub account
- Not logged into x.com (no ct0 cookie)
- Browser session required for bilibili follow
- Browser session required for bilibili following
- 未获取到课程列表
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/71c86446e344dcf9.
Report an issue: GitHub.