diff --git a/auth.js b/auth.js index 0b4385a..3b1f7ee 100644 --- a/auth.js +++ b/auth.js @@ -269,7 +269,22 @@ if (signupForm) { return; } - window.location.href = getMainPagePath("signin.html"); + // if username already exists + const userExists = users.some(user => user.email === email); + + if (userExists) { + error.textContent = "User already exists!"; + return; + } + + // new user + const newUser = { username, email, password }; + users.push(newUser); + localStorage.setItem("users", JSON.stringify(users)); + + localStorage.setItem("loggedIn", "true"); + localStorage.setItem("loggedInUser", username); + window.location.href = getMainPagePath("index.html"); }); } diff --git a/index.html b/index.html index e6d9bf2..2c21fb2 100644 --- a/index.html +++ b/index.html @@ -1,4 +1,4 @@ - +
@@ -168,12 +168,12 @@