From 5c7a945be0ec96d6ee03ea1090a2b59c630a2dbe Mon Sep 17 00:00:00 2001 From: nocci Date: Wed, 31 Dec 2025 13:04:00 +0000 Subject: [PATCH] fix: fall back to manual login when epic device code api fails --- README.md | 1 + epic-claimer-new.js | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2f5b4c6..911bccd 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ Common options: - `TIMEOUT`, `LOGIN_TIMEOUT` (seconds) - Epic: `EG_MODE=legacy|new` (legacy Playwright flow or neuer API-getriebener Claimer), `EG_PARENTALPIN`, `EG_EMAIL`, `EG_PASSWORD`, `EG_OTPKEY` - Epic (new mode): Cookies werden unter `data/browser/epic-cookies.json` persistiert; OAuth Device Code Flow benötigt ggf. einmalige Freigabe im Browser. + - Falls Device-Code-Endpunkt nicht erreichbar ist (404/Bad Request), fällt der neue Modus automatisch auf manuellen Browser-Login zurück. - Login: `EMAIL`, `PASSWORD` global; per store `EG_EMAIL`, `EG_PASSWORD`, `EG_OTPKEY`, `PG_EMAIL`, `PG_PASSWORD`, `PG_OTPKEY`, `GOG_EMAIL`, `GOG_PASSWORD` - Prime Gaming: `PG_REDEEM=1` (auto-redeem keys, experimental), `PG_CLAIMDLC=1`, `PG_TIMELEFT=` to skip long-remaining offers - Screenshots: `SCREENSHOTS_DIR` (default `data/screenshots`) diff --git a/epic-claimer-new.js b/epic-claimer-new.js index 9d8c08f..ff47640 100644 --- a/epic-claimer-new.js +++ b/epic-claimer-new.js @@ -80,10 +80,16 @@ const getValidAuth = async ({ otpKey, reuseCookies, cookiesPath }) => { } console.log('🔐 Starting fresh OAuth device flow (manual approval required)...'); - const deviceResponse = await axios.post('https://api.epicgames.dev/epic/oauth/deviceCode', { - client_id: '34a02cf8f4414e29b159cdd02e6184bd', - scope: 'account.basicprofile account.userentitlements', - }); + let deviceResponse; + try { + deviceResponse = await axios.post('https://api.epicgames.dev/epic/oauth/deviceCode', { + client_id: '34a02cf8f4414e29b159cdd02e6184bd', + scope: 'account.basicprofile account.userentitlements', + }); + } catch (e) { + console.error('Device code flow failed (fallback to manual login):', e.response?.status || e.message); + return { bearerToken: null, cookies: [] }; + } const { device_code, user_code, verification_uri_complete } = deviceResponse.data; console.log(`📱 Open: ${verification_uri_complete}`); console.log(`💳 Code: ${user_code}`); @@ -258,8 +264,12 @@ export const claimEpicGamesNew = async () => { cookiesPath: COOKIES_PATH, }); - await context.addCookies(auth.cookies); - console.log('✅ Cookies loaded:', auth.cookies.length); + if (auth.cookies?.length) { + await context.addCookies(auth.cookies); + console.log('✅ Cookies loaded:', auth.cookies.length); + } else { + console.log('⚠️ No cookies loaded; using manual login via browser.'); + } await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); user = await ensureLoggedIn(page, context);