This commit is contained in:
jjbrunton committed 2026-01-05 15:13:59 +00:00
1 parent 2a78f65b09
commit 00934fecbb
1 file changed
+15 -9
+15 -9
View File
@@ -176,6 +176,12 @@ export class BrowserClient {
// Give cookies/time to settle
await page.waitForTimeout(2000);
const isValid = await this.isSessionValid();
if (isValid) {
this.logger.info('Login successful!');
return true;
}
const obstacleInfo = await this.detectLoginObstacles(page);
if (obstacleInfo.twoFactor) {
this.logger.error('Login requires 2FA. Please run "npm run login" locally to complete it once.');
@@ -193,13 +199,6 @@ export class BrowserClient {
return false;
}
// Confirm auth via UI or API check
const isValid = await this.isSessionValid();
if (isValid) {
this.logger.info('Login successful!');
return true;
}
// Check for error messages
const errorContent = obstacleInfo.errorText;
@@ -231,13 +230,20 @@ export class BrowserClient {
.map((el) => el.textContent?.trim())
.filter((text) => text && text.length > 0) as string[];
const isLoginContext =
window.location.href.includes('/login') ||
Boolean(
document.querySelector(
'input[name="username"], input[name="password"], form[action*="login"], [data-testid="login-form"]'
)
);
const otpInput = document.querySelector('input[name="otp"], input[autocomplete="one-time-code"], input[type="tel"][maxlength="6"]');
const captchaElement = document.querySelector('iframe[src*="captcha"], iframe[src*="recaptcha"], [data-sitekey], #captcha, .captcha');
return {
errorText: errorCandidates[0] ?? null,
hasOtp: Boolean(otpInput),
hasCaptcha: Boolean(captchaElement),
hasOtp: Boolean(otpInput) && isLoginContext,
hasCaptcha: Boolean(captchaElement) && isLoginContext,
};
});