From 7c7ec20e960278f9c7641e34ace5312b1d723ac2 Mon Sep 17 00:00:00 2001 From: Tristan Ehron Tumbaga Date: Mon, 25 Nov 2024 18:40:21 +0800 Subject: [PATCH] Fix: Bug in PR code, to redirect user to home-page after login --- js/login-sign-in.js | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/js/login-sign-in.js b/js/login-sign-in.js index 7498075..a75b2f8 100644 --- a/js/login-sign-in.js +++ b/js/login-sign-in.js @@ -106,24 +106,26 @@ function checkLoginValidation(e) { let massege = document.querySelector('#error-massage'); let password = document.querySelector('#pwd').value; let userName = document.querySelector('#email').value; - console.log(userName); // Is this a debugging statement? let user = JSON.parse(localStorage.getItem(userName)); if (user == null || user.password != password) { - massege.classList.remove('hide'); - return; + massege.classList.remove('hide'); + return; } const currentUser = { - firstName: user['firstName'], - userName: userName, - highScore: user.highScore, - secondScore: user.secondScore, + firstName: user['firstName'], + userName: userName, + highScore: user.highScore, + secondScore: user.secondScore, }; sessionStorage.setItem('currentUser', JSON.stringify(currentUser)); massege.classList.add('hide'); - modalLogin.hide() - updateHeloUser(); + modalLogin.hide(); + + // Redirect to home page + window.location.href = "../html/icy-tower-home.html"; } + function checkEqualtoPwd() { let pw = document.querySelector('#pasword-first').value; if (pw != document.querySelector('#verify-pwd').value) { @@ -261,13 +263,16 @@ checkLoginStatus(); // Assuming this function is called when the user logs in function loginUser(username) { - // Simulate logging in - sessionStorage.setItem('currentUser', username); - - // Update the state of the link immediately after login - checkLoginStatus(); - - // Optionally, hide the login message - loginMessage.style.display = 'none'; + // Simulate logging in + sessionStorage.setItem('currentUser', username); + + // Update the state of the link immediately after login + checkLoginStatus(); + + // Optionally, hide the login message + loginMessage.style.display = 'none'; + + // Redirect to the home page (or any other page) + window.location.href = '../html/icy-tower-home.html'; // Replace 'home.html' with your home page URL }