fix: auto-fill epic login in new claimer to avoid timeout
This commit is contained in:
parent
d05c184156
commit
bf0625de8b
1 changed files with 37 additions and 2 deletions
|
|
@ -113,12 +113,46 @@ const getValidAuth = async ({ email, password, otpKey, reuseCookies, cookiesPath
|
|||
};
|
||||
|
||||
const ensureLoggedIn = async (page, context) => {
|
||||
while (await page.locator('egs-navigation').getAttribute('isloggedin') != 'true') {
|
||||
console.error('Not signed in anymore. Please login in the browser or here in the terminal.');
|
||||
const isLoggedIn = async () => (await page.locator('egs-navigation').getAttribute('isloggedin')) === 'true';
|
||||
|
||||
const attemptAutoLogin = async () => {
|
||||
// Epic login form
|
||||
if (!cfg.eg_email || !cfg.eg_password) return false;
|
||||
try {
|
||||
await page.waitForSelector('input[name="email"]', { timeout: cfg.login_visible_timeout }).catch(() => {});
|
||||
const emailField = page.locator('input[name="email"], input#email');
|
||||
const passwordField = page.locator('input[name="password"], input#password');
|
||||
if (await emailField.count()) await emailField.fill(cfg.eg_email);
|
||||
if (await passwordField.count()) {
|
||||
await passwordField.fill(cfg.eg_password);
|
||||
await page.click('button[type="submit"]');
|
||||
}
|
||||
// MFA step
|
||||
try {
|
||||
await page.waitForURL('**/id/login/mfa**', { timeout: cfg.login_timeout });
|
||||
const otp = cfg.eg_otpkey && authenticator.generate(cfg.eg_otpkey) || await prompt({ type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 6 || 'The code must be 6 digits!' });
|
||||
await page.locator('input[name="code-input-0"]').pressSequentially(otp.toString());
|
||||
await page.click('button[type="submit"]');
|
||||
} catch {
|
||||
// no MFA
|
||||
}
|
||||
await page.waitForURL('**/free-games', { timeout: cfg.login_timeout }).catch(() => {});
|
||||
return await isLoggedIn();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
while (!await isLoggedIn()) {
|
||||
console.error('Not signed in anymore. Trying automatic login, otherwise please login in the browser.');
|
||||
if (cfg.novnc_port) console.info(`Open http://localhost:${cfg.novnc_port} to login inside the docker container.`);
|
||||
if (!cfg.debug) context.setDefaultTimeout(cfg.login_timeout);
|
||||
console.info(`Login timeout is ${cfg.login_timeout / 1000} seconds!`);
|
||||
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' });
|
||||
|
||||
const logged = await attemptAutoLogin();
|
||||
if (logged) break;
|
||||
|
||||
console.log('Waiting for manual login in the browser (cookies might be invalid).');
|
||||
await notify('epic-games (new): please login in browser; cookies invalid or expired.');
|
||||
if (cfg.headless) {
|
||||
|
|
@ -128,6 +162,7 @@ const ensureLoggedIn = async (page, context) => {
|
|||
}
|
||||
await page.waitForTimeout(cfg.login_timeout);
|
||||
}
|
||||
|
||||
const user = await page.locator('egs-navigation').getAttribute('displayname');
|
||||
console.log(`Signed in as ${user}`);
|
||||
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue