Update
This commit is contained in:
1 parent
2a78f65b09
commit
00934fecbb
1 file changed
+15
-9
+15
-9
@@ -176,6 +176,12 @@ export class BrowserClient {
|
|||||||
// Give cookies/time to settle
|
// Give cookies/time to settle
|
||||||
await page.waitForTimeout(2000);
|
await page.waitForTimeout(2000);
|
||||||
|
|
||||||
|
const isValid = await this.isSessionValid();
|
||||||
|
if (isValid) {
|
||||||
|
this.logger.info('Login successful!');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const obstacleInfo = await this.detectLoginObstacles(page);
|
const obstacleInfo = await this.detectLoginObstacles(page);
|
||||||
if (obstacleInfo.twoFactor) {
|
if (obstacleInfo.twoFactor) {
|
||||||
this.logger.error('Login requires 2FA. Please run "npm run login" locally to complete it once.');
|
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;
|
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
|
// Check for error messages
|
||||||
const errorContent = obstacleInfo.errorText;
|
const errorContent = obstacleInfo.errorText;
|
||||||
|
|
||||||
@@ -231,13 +230,20 @@ export class BrowserClient {
|
|||||||
.map((el) => el.textContent?.trim())
|
.map((el) => el.textContent?.trim())
|
||||||
.filter((text) => text && text.length > 0) as string[];
|
.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 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');
|
const captchaElement = document.querySelector('iframe[src*="captcha"], iframe[src*="recaptcha"], [data-sitekey], #captcha, .captcha');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
errorText: errorCandidates[0] ?? null,
|
errorText: errorCandidates[0] ?? null,
|
||||||
hasOtp: Boolean(otpInput),
|
hasOtp: Boolean(otpInput) && isLoginContext,
|
||||||
hasCaptcha: Boolean(captchaElement),
|
hasCaptcha: Boolean(captchaElement) && isLoginContext,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user