Make Signup Process work like login

This commit is contained in:
James Musselman 2023-11-29 21:03:28 -06:00
parent 4093202bf5
commit 8e10778d8e

View file

@ -68,7 +68,6 @@ function checkUsernameAvailability() {
xhr.send(); xhr.send();
} }
function submitSignup() { function submitSignup() {
// Disable the button to prevent multiple clicks // Disable the button to prevent multiple clicks
submitBtn.disabled = true; submitBtn.disabled = true;
@ -93,23 +92,24 @@ function submitSignup() {
formData.append("password", password); formData.append("password", password);
// Send the signup request as form data // Send the signup request as form data
fetch("/signup", { const xhr = new XMLHttpRequest();
method: "POST", xhr.open("POST", "/signup", true);
body: formData
}) xhr.onreadystatechange = function () {
.then(response => { if (xhr.readyState === 4) {
if (response.ok) { if (xhr.status === 200) {
return response.json(); // Signup successful
console.log("Signup successful");
window.location.href = "/welcome"; // Redirect to success page
} else { } else {
throw new Error("Signup request failed"); // Signup failed, display the error message
const response = JSON.parse(xhr.responseText);
console.error("Signup failed:", response.error);
} }
}) }
.then(() => { };
window.location.href = "/welcome";
}) xhr.send(formData);
.catch(error => {
console.error(error);
});
// Enable the button and remove the spinner after 5 seconds // Enable the button and remove the spinner after 5 seconds
setTimeout(function () { setTimeout(function () {
@ -121,6 +121,7 @@ function submitSignup() {
function sleep(ms) { function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms)); return new Promise(resolve => setTimeout(resolve, ms));
} }