90 lines
2.6 KiB
JavaScript
90 lines
2.6 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
// Simple debug script to test the login flow
|
|
const https = require('https');
|
|
const http = require('http');
|
|
|
|
const BASE_URL = 'https://portal.monacousa.org';
|
|
|
|
async function makeRequest(url, options = {}) {
|
|
return new Promise((resolve, reject) => {
|
|
const protocol = url.startsWith('https') ? https : http;
|
|
|
|
const req = protocol.request(url, {
|
|
method: options.method || 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'User-Agent': 'Debug-Script/1.0',
|
|
...options.headers
|
|
}
|
|
}, (res) => {
|
|
let data = '';
|
|
res.on('data', chunk => data += chunk);
|
|
res.on('end', () => {
|
|
resolve({
|
|
status: res.statusCode,
|
|
headers: res.headers,
|
|
body: data
|
|
});
|
|
});
|
|
});
|
|
|
|
req.on('error', reject);
|
|
|
|
if (options.body) {
|
|
req.write(JSON.stringify(options.body));
|
|
}
|
|
|
|
req.end();
|
|
});
|
|
}
|
|
|
|
async function testLoginFlow() {
|
|
console.log('🔍 Testing MonacoUSA Portal Login Flow');
|
|
console.log('=====================================\n');
|
|
|
|
try {
|
|
// Test 1: Health check
|
|
console.log('1. Testing health endpoint...');
|
|
const health = await makeRequest(`${BASE_URL}/api/health`);
|
|
console.log(` Status: ${health.status}`);
|
|
console.log(` Response: ${health.body.substring(0, 100)}...\n`);
|
|
|
|
// Test 2: Session check (should be unauthenticated)
|
|
console.log('2. Testing session endpoint...');
|
|
const session = await makeRequest(`${BASE_URL}/api/auth/session`);
|
|
console.log(` Status: ${session.status}`);
|
|
console.log(` Response: ${session.body.substring(0, 100)}...\n`);
|
|
|
|
// Test 3: Login attempt
|
|
console.log('3. Testing direct login...');
|
|
const login = await makeRequest(`${BASE_URL}/api/auth/direct-login`, {
|
|
method: 'POST',
|
|
body: {
|
|
username: 'present',
|
|
password: 'your-password-here',
|
|
rememberMe: false
|
|
}
|
|
});
|
|
console.log(` Status: ${login.status}`);
|
|
console.log(` Headers: ${JSON.stringify(login.headers, null, 2)}`);
|
|
console.log(` Response: ${login.body.substring(0, 200)}...\n`);
|
|
|
|
// Test 4: Check if we can access dashboard
|
|
console.log('4. Testing dashboard access...');
|
|
const dashboard = await makeRequest(`${BASE_URL}/dashboard`, {
|
|
headers: {
|
|
'Cookie': login.headers['set-cookie'] ? login.headers['set-cookie'].join('; ') : ''
|
|
}
|
|
});
|
|
console.log(` Status: ${dashboard.status}`);
|
|
console.log(` Response: ${dashboard.body.substring(0, 100)}...\n`);
|
|
|
|
} catch (error) {
|
|
console.error('❌ Error during testing:', error.message);
|
|
}
|
|
}
|
|
|
|
// Run the test
|
|
testLoginFlow();
|