feat(myTischtennis): implement session restoration for browser automation login
- Enhanced the loginWithBrowserAutomation method to accept an options parameter for restoring a saved Playwright session, allowing users to bypass CAPTCHA if the session is still valid. - Added a new playwrightStorageState field in the MyTischtennis model to store the encrypted browser storage state, facilitating session persistence. - Updated myTischtennisService to utilize the saved storage state during login attempts, improving user experience by reducing unnecessary CAPTCHA challenges.
This commit is contained in:
@@ -60,7 +60,12 @@ class MyTischtennisService {
|
||||
loginResult = await myTischtennisClient.login(email, password);
|
||||
if (!loginResult.success && loginResult.requiresCaptcha) {
|
||||
console.log('[myTischtennisService.upsertAccount] CAPTCHA-Fehler, versuche Playwright-Fallback...');
|
||||
const playwrightResult = await myTischtennisClient.loginWithBrowserAutomation(email, password);
|
||||
// Load saved browser state so we can skip the CAPTCHA if the previous session is still valid.
|
||||
const existingAccount = await MyTischtennis.findOne({ where: { userId } });
|
||||
const savedStorageState = existingAccount?.playwrightStorageState ?? null;
|
||||
const playwrightResult = await myTischtennisClient.loginWithBrowserAutomation(
|
||||
email, password, { savedStorageState }
|
||||
);
|
||||
if (playwrightResult.success) {
|
||||
loginResult = playwrightResult;
|
||||
} else {
|
||||
@@ -106,6 +111,9 @@ class MyTischtennisService {
|
||||
account.expiresAt = loginResult.expiresAt;
|
||||
account.cookie = loginResult.cookie;
|
||||
account.userData = loginResult.user;
|
||||
if (loginResult.storageState) {
|
||||
account.playwrightStorageState = loginResult.storageState;
|
||||
}
|
||||
|
||||
// Hole Club-ID und Federation
|
||||
const profileResult = await myTischtennisClient.getUserProfile(loginResult.cookie);
|
||||
@@ -139,6 +147,9 @@ class MyTischtennisService {
|
||||
accountData.expiresAt = loginResult.expiresAt;
|
||||
accountData.cookie = loginResult.cookie;
|
||||
accountData.userData = loginResult.user;
|
||||
if (loginResult.storageState) {
|
||||
accountData.playwrightStorageState = loginResult.storageState;
|
||||
}
|
||||
|
||||
// Hole Club-ID
|
||||
const profileResult = await myTischtennisClient.getUserProfile(loginResult.cookie);
|
||||
@@ -242,7 +253,10 @@ class MyTischtennisService {
|
||||
if (!effectiveLoginResult.success && effectiveLoginResult.requiresCaptcha) {
|
||||
console.log('[myTischtennisService.verifyLogin] CAPTCHA-Fehler, versuche Playwright-Fallback...');
|
||||
try {
|
||||
const playwrightResult = await myTischtennisClient.loginWithBrowserAutomation(account.email, password);
|
||||
const savedStorageState = account.playwrightStorageState ?? null;
|
||||
const playwrightResult = await myTischtennisClient.loginWithBrowserAutomation(
|
||||
account.email, password, { savedStorageState }
|
||||
);
|
||||
if (playwrightResult.success) {
|
||||
effectiveLoginResult = playwrightResult;
|
||||
} else {
|
||||
@@ -282,6 +296,9 @@ class MyTischtennisService {
|
||||
account.expiresAt = effectiveLoginResult.expiresAt;
|
||||
account.cookie = effectiveLoginResult.cookie;
|
||||
account.userData = effectiveLoginResult.user;
|
||||
if (effectiveLoginResult.storageState) {
|
||||
account.playwrightStorageState = effectiveLoginResult.storageState;
|
||||
}
|
||||
|
||||
// Hole Club-ID und Federation
|
||||
const profileResult = await myTischtennisClient.getUserProfile(effectiveLoginResult.cookie);
|
||||
|
||||
Reference in New Issue
Block a user