So I am using this file as a login page for a web application. But it doesn't seem like it does anything, the URL is changed but no console message is printed out and it does not show the proper resource in the web browser. The only thing that I can see in the browser when testing it is a "200" code is returned with an "OK" message.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Start Page</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<div class="container">
<h1>Welcome to the Travel Tracker</h1>
<form id="login-form">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<button type="submit">Login</button>
</form>
<p>Don't have an account? <a href="register.html">Register here</a>.</p>
</div>
<script>
// Handle form submission
document.getElementById('login-form').addEventListener('submit', async (event) => {
event.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
try {
const response = await axios.post('/api/login', { username, password });
if (response.data.response === "Login successful") {
console.log(`Successful login for user: ${username}`);
// Redirect to the main app page on successful login
//Send user to map.html with username as a query parameter
window.location.replace(`https://localhost/map.html?username=${encodeURIComponent(username)}&t=${Date.now()}`);
} else {
console.log(`Failed login attempt for user: ${username}`);
alert('Invalid login credentials. Please try again.');
}
} catch (error) {
console.error(error);
alert('An error occurred while logging in. Please try again.');
}
});
</script>
</body>
</html>
I tried logging in on this page as a user which exists in the applications database. I have tried writing a lot of console logs to be able to find the error but none of them are printed.