refactor(auth): add device auth reuse for legacy account migration
All checks were successful
build-and-push / lint (push) Successful in 8s
build-and-push / sonar (push) Successful in 21s
build-and-push / docker (push) Successful in 11s

- imports device auth utility functions
- adds logic to reuse Epic Games device authentication from legacy mode
- loads device auth cookies (EPIC_SSO_RM, EPIC_DEVICE, EPIC_SESSION_AP) when available
- falls back to regular authentication if device auth is not present

This enables seamless transition for users migrating from legacy authentication while maintaining backward compatibility.
This commit is contained in:
nocci 2026-03-08 11:18:28 +00:00
parent d55706c5f3
commit 0a5f40341b

View file

@ -14,6 +14,7 @@ import {
handleSIGINT,
} from './src/util.js';
import { cfg } from './src/config.js';
import { getDeviceAuths, setAccountAuth } from './src/device-auths.js';
const URL_CLAIM = 'https://store.epicgames.com/en-US/free-games';
@ -329,12 +330,26 @@ export const claimEpicGamesNew = async () => {
const page = context.pages().length ? context.pages()[0] : await context.newPage();
await page.setViewportSize({ width: cfg.width, height: cfg.height });
// Use device auths if available (from legacy mode)
const deviceAuths = await getDeviceAuths();
if (deviceAuths && cfg.eg_email) {
const accountAuth = deviceAuths[cfg.eg_email];
if (accountAuth) {
console.log('🔄 Reusing device auth from legacy mode');
const cookies = [
{ name: 'EPIC_SSO_RM', value: accountAuth.deviceAuth?.refreshToken || '', domain: '.epicgames.com', path: '/' },
{ name: 'EPIC_DEVICE', value: accountAuth.deviceAuth?.deviceId || '', domain: '.epicgames.com', path: '/' },
{ name: 'EPIC_SESSION_AP', value: accountAuth.deviceAuth?.accountId || '', domain: '.epicgames.com', path: '/' },
];
await context.addCookies(cookies);
console.log('✅ Device auth cookies loaded');
}
}
let user;
try {
const auth = await getValidAuth({
email: cfg.eg_email,
password: cfg.eg_password,
otpKey: cfg.eg_otpkey,
reuseCookies: true,
cookiesPath: COOKIES_PATH,