fix: fall back to manual login when epic device code api fails
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 11s
build-and-push / docker (push) Successful in 1m9s

This commit is contained in:
nocci 2025-12-31 13:04:00 +00:00
parent 051363ed5f
commit 5c7a945be0
2 changed files with 17 additions and 6 deletions

View file

@ -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);