Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
}

Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">

<head>
Expand Down Expand Up @@ -168,12 +168,12 @@ <h3>Tic Tac Toe</h3>

<!-- AUTH SYSTEM -->
<script src="auth.js"></script>
<script src="script.js"></script>
<script>
checkAuth(); // protect page
showLoggedInUser(); // show username
</script>

<script src="script.js"></script>

</body>

Expand Down
2 changes: 1 addition & 1 deletion signin.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ <h2>Login</h2>
}
</script>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ <h2>Create Account</h2>
}
</script>
</body>
</html>
</html>
Loading