
async function main() {
    const email = `test_${Date.now()}@example.com`;
    const password = 'password123';

    console.log(`Registering ${email}...`);
    try {
        const regRes = await fetch('http://localhost:3001/api/auth/register', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ email, password })
        });
        const regData = await regRes.json();
        console.log('Register:', regRes.status, regData);

        if (!regData.success) {
            console.error('Registration failed');
            return;
        }

        console.log('Logging in...');
        const loginRes = await fetch('http://localhost:3001/api/auth/login', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ email, password })
        });
        const loginData = await loginRes.json();
        console.log('Login:', loginRes.status, loginData.success ? 'Success' : 'Fail');

    } catch (e) {
        console.error('Fetch failed:', e);
    }
}

main();
