diff --git a/prime-gaming.js b/prime-gaming.js index 0ee1fce..e5a5984 100644 --- a/prime-gaming.js +++ b/prime-gaming.js @@ -34,6 +34,17 @@ await page.setViewportSize({ width: cfg.width, height: cfg.height }); // workaro const notify_games = []; 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 otpLocator = p.locator('#auth-mfa-otpcode, input[name=otpCode]'); 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]); }; -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 { await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); // default 'load' takes forever const handleDirectLoginPage = async () => {