Make Signup Process work like login
This commit is contained in:
parent
4093202bf5
commit
8e10778d8e
1 changed files with 18 additions and 17 deletions
|
@ -68,7 +68,6 @@ function checkUsernameAvailability() {
|
|||
xhr.send();
|
||||
}
|
||||
|
||||
|
||||
function submitSignup() {
|
||||
// Disable the button to prevent multiple clicks
|
||||
submitBtn.disabled = true;
|
||||
|
@ -93,23 +92,24 @@ function submitSignup() {
|
|||
formData.append("password", password);
|
||||
|
||||
// Send the signup request as form data
|
||||
fetch("/signup", {
|
||||
method: "POST",
|
||||
body: formData
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "/signup", true);
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
// Signup successful
|
||||
console.log("Signup successful");
|
||||
window.location.href = "/welcome"; // Redirect to success page
|
||||
} 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";
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send(formData);
|
||||
|
||||
// Enable the button and remove the spinner after 5 seconds
|
||||
setTimeout(function () {
|
||||
|
@ -121,6 +121,7 @@ function submitSignup() {
|
|||
|
||||
|
||||
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue