Update server.js
Browse files
server.js
CHANGED
|
@@ -63,33 +63,51 @@ async function performLogin() {
|
|
| 63 |
// Wait for form to be visible
|
| 64 |
await page.waitForSelector('form#login', { timeout: 10000 });
|
| 65 |
|
| 66 |
-
//
|
|
|
|
| 67 |
await page.type('input[name="mail"]', process.env.LOGIN_EMAIL, { delay: 100 });
|
| 68 |
await new Promise(resolve => setTimeout(resolve, 500));
|
| 69 |
|
|
|
|
| 70 |
await page.type('input[name="password"]', process.env.LOGIN_PASSWORD, { delay: 100 });
|
| 71 |
-
await new Promise(resolve => setTimeout(resolve,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
//
|
| 74 |
-
await
|
| 75 |
|
| 76 |
-
//
|
| 77 |
-
|
|
|
|
| 78 |
|
| 79 |
-
//
|
| 80 |
const loginSuccess = await page.evaluate(() => {
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
});
|
| 86 |
|
| 87 |
-
if (loginSuccess) {
|
| 88 |
isLoggedIn = true;
|
| 89 |
-
console.log('Login successful');
|
| 90 |
return true;
|
| 91 |
} else {
|
| 92 |
-
console.log('Login
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
return false;
|
| 94 |
}
|
| 95 |
} catch (error) {
|
|
|
|
| 63 |
// Wait for form to be visible
|
| 64 |
await page.waitForSelector('form#login', { timeout: 10000 });
|
| 65 |
|
| 66 |
+
// Clear any existing input and fill credentials
|
| 67 |
+
await page.click('input[name="mail"]', { clickCount: 3 });
|
| 68 |
await page.type('input[name="mail"]', process.env.LOGIN_EMAIL, { delay: 100 });
|
| 69 |
await new Promise(resolve => setTimeout(resolve, 500));
|
| 70 |
|
| 71 |
+
await page.click('input[name="password"]', { clickCount: 3 });
|
| 72 |
await page.type('input[name="password"]', process.env.LOGIN_PASSWORD, { delay: 100 });
|
| 73 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
| 74 |
+
|
| 75 |
+
// Submit form and wait for navigation
|
| 76 |
+
await Promise.all([
|
| 77 |
+
page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 15000 }),
|
| 78 |
+
page.click('input[type="submit"]')
|
| 79 |
+
]);
|
| 80 |
|
| 81 |
+
// Additional wait for any redirects
|
| 82 |
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
| 83 |
|
| 84 |
+
// Check current URL and page content for login success
|
| 85 |
+
const currentUrl = page.url();
|
| 86 |
+
console.log('Current URL after login:', currentUrl);
|
| 87 |
|
| 88 |
+
// More comprehensive login success check
|
| 89 |
const loginSuccess = await page.evaluate(() => {
|
| 90 |
+
const url = window.location.href;
|
| 91 |
+
const hasLogoutButton = document.querySelector('[href*="logout"]') !== null;
|
| 92 |
+
const hasUserMenu = document.querySelector('.user-menu, .dropdown-toggle') !== null;
|
| 93 |
+
const notOnLoginPage = !url.includes('/auth/login');
|
| 94 |
+
const hasWelcomeText = document.body.innerText.toLowerCase().includes('welcome') ||
|
| 95 |
+
document.body.innerText.toLowerCase().includes('dashboard');
|
| 96 |
+
|
| 97 |
+
return notOnLoginPage || hasLogoutButton || hasUserMenu || hasWelcomeText;
|
| 98 |
});
|
| 99 |
|
| 100 |
+
if (loginSuccess && !currentUrl.includes('/auth/login')) {
|
| 101 |
isLoggedIn = true;
|
| 102 |
+
console.log('Login successful - authenticated session established');
|
| 103 |
return true;
|
| 104 |
} else {
|
| 105 |
+
console.log('Login failed - still on login page or no auth indicators found');
|
| 106 |
+
|
| 107 |
+
// Debug: Get page content to see what happened
|
| 108 |
+
const pageText = await page.evaluate(() => document.body.innerText);
|
| 109 |
+
console.log('Page content snippet:', pageText.substring(0, 500));
|
| 110 |
+
|
| 111 |
return false;
|
| 112 |
}
|
| 113 |
} catch (error) {
|