Add login submission from front-end

This commit is contained in:
2025-12-03 16:34:53 +01:00
parent da011dbdcd
commit 63a9c13941
3 changed files with 69 additions and 36 deletions

View File

@@ -22,24 +22,42 @@
</head>
<body>
<header>
<h1>Welcome!</h1>
</header>
<main>
<input placeholder="Username">
<input id="username-field" placeholder="Username">
<br>
<input placeholder="Password">
<input id="password-field" placeholder="Password">
<br>
<button>Connect</button>
<button id="connect-button">Connect</button>
</main>
<footer>
</footer>
<script>
let btn = document.getElementById("connect-button");
btn.addEventListener("click", () => {
let username = document.getElementById("username-field").value;
let pwd = document.getElementById("password-field").value;
let data = {
username: username,
password: pwd
};
fetch("/login", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.then(response => response.text())
.then(result => {
console.log("Server response:", result);
})
.catch(error => {
console.error("Error:", error);
});
});
</script>
</body>
</html>