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 @@

Tic Tac Toe

+ - diff --git a/signin.html b/signin.html index 3ae8c29..4a9ee53 100644 --- a/signin.html +++ b/signin.html @@ -38,4 +38,4 @@

Login

} - + \ No newline at end of file diff --git a/signup.html b/signup.html index 1a5a9e2..1dcc737 100644 --- a/signup.html +++ b/signup.html @@ -47,4 +47,4 @@

Create Account

} - + \ No newline at end of file