fix: define MFA helper before use
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 12s
build-and-push / docker (push) Successful in 1m8s

This commit is contained in:
nocci 2025-12-31 10:58:27 +00:00
parent 2aaa0cdd1a
commit 0340873d91

View file

@ -34,6 +34,17 @@ await page.setViewportSize({ width: cfg.width, height: cfg.height }); // workaro
const notify_games = []; const notify_games = [];
let user; let user;
const handleMFA = async p => {
const otpField = p.locator('#auth-mfa-otpcode, input[name=otpCode]');
if (!await otpField.count()) return false;
console.log('Two-Step Verification - enter the One Time Password (OTP), e.g. generated by your Authenticator App');
await p.locator('#auth-mfa-remember-device, [name=rememberDevice]').check().catch(() => {});
const otp = cfg.pg_otpkey && authenticator.generate(cfg.pg_otpkey) || await prompt({ type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 6 || 'The code must be 6 digits!' }); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them
await otpField.first().pressSequentially(otp.toString());
await p.locator('input[type="submit"], button[type="submit"]').first().click();
return true;
};
const waitForSignedInOrMFA = async p => { const waitForSignedInOrMFA = async p => {
const otpLocator = p.locator('#auth-mfa-otpcode, input[name=otpCode]'); const otpLocator = p.locator('#auth-mfa-otpcode, input[name=otpCode]');
const waitSignedIn = p.waitForURL('**/claims/**signedIn=true', { timeout: cfg.login_timeout }).then(() => true).catch(() => false); const waitSignedIn = p.waitForURL('**/claims/**signedIn=true', { timeout: cfg.login_timeout }).then(() => true).catch(() => false);
@ -54,17 +65,6 @@ const waitForSignedInOrMFA = async p => {
await Promise.race([waitSignedIn, waitMFA]); await Promise.race([waitSignedIn, waitMFA]);
}; };
const handleMFA = async p => {
const otpField = p.locator('#auth-mfa-otpcode, input[name=otpCode]');
if (!await otpField.count()) return false;
console.log('Two-Step Verification - enter the One Time Password (OTP), e.g. generated by your Authenticator App');
await p.locator('#auth-mfa-remember-device, [name=rememberDevice]').check().catch(() => {});
const otp = cfg.pg_otpkey && authenticator.generate(cfg.pg_otpkey) || await prompt({ type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 6 || 'The code must be 6 digits!' }); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them
await otpField.first().pressSequentially(otp.toString());
await p.locator('input[type="submit"], button[type="submit"]').first().click();
return true;
};
try { try {
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); // default 'load' takes forever await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); // default 'load' takes forever
const handleDirectLoginPage = async () => { const handleDirectLoginPage = async () => {