-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
// window.onload = () => { | ||
// const userId = sessionStorage.getItem('userId'); | ||
// console.log("this is the userID: ", {userId}); | ||
// if (!userId) { | ||
// window.location.href = '../pages/login.html'; | ||
// } else { | ||
// fetch(`/get-username?uid=${userId}`) | ||
// .then(resp => resp.json()) | ||
// .then(data => { | ||
// // Assuming 'data' has a 'username' property with the user's name | ||
// const username = data.username; | ||
// const usernameElement = document.querySelector('.user-disp'); | ||
// // Replace the placeholder text with the actual username | ||
// usernameElement.textContent = `Welcome Back, ${username}.`; | ||
// }) | ||
// .catch(error => { | ||
// console.error("Error:", error); | ||
// }); | ||
// } | ||
// } | ||
|
||
window.onload = () => { | ||
const userId = sessionStorage.getItem('userId'); | ||
console.log("this is the userID: ", userId); | ||
console.log("this is the userID: ", {userId}); | ||
if (!userId) { | ||
window.location.href = '/pages/login.html'; // This path might need to be adjusted depending on your structure | ||
window.location.href = '../pages/login.html'; | ||
} else { | ||
fetch(`/get-username?uid=${userId}`) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! Status: ${response.status}`); | ||
} | ||
return response.text(); // Temporarily get raw text to see what's actually coming back | ||
}) | ||
.then(text => { | ||
console.log("Received text: ", text); // Log out the raw text response | ||
return JSON.parse(text); // Parse text to JSON | ||
}) | ||
.then(resp => resp.json()) | ||
.then(data => { | ||
// Assuming 'data' has a 'username' property with the user's name | ||
const username = data.username; | ||
const usernameElement = document.querySelector('.user-disp'); | ||
if(data && data.username) { | ||
usernameElement.textContent = `Welcome Back, ${data.username}`; | ||
} else { | ||
throw new Error('Username not found in response'); | ||
} | ||
// Replace the placeholder text with the actual username | ||
usernameElement.textContent = `Welcome Back, ${username}.`; | ||
}) | ||
.catch(error => { | ||
console.error("Error:", error); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
// window.onload = () => { | ||
// const userId = sessionStorage.getItem('userId'); | ||
// console.log("this is the userID: ", userId); | ||
// if (!userId) { | ||
// window.location.href = '/pages/login.html'; // This path might need to be adjusted depending on your structure | ||
// } else { | ||
// fetch(`/get-username?uid=${userId}`) | ||
// .then(response => { | ||
// if (!response.ok) { | ||
// throw new Error(`HTTP error! Status: ${response.status}`); | ||
// } | ||
// return response.text(); // Temporarily get raw text to see what's actually coming back | ||
// }) | ||
// .then(text => { | ||
// console.log("Received text: ", text); // Log out the raw text response | ||
// return JSON.parse(text); // Parse text to JSON | ||
// }) | ||
// .then(data => { | ||
// const usernameElement = document.querySelector('.user-disp'); | ||
// if(data && data.username) { | ||
// usernameElement.textContent = `Welcome Back, ${data.username}`; | ||
// } else { | ||
// throw new Error('Username not found in response'); | ||
// } | ||
// }) | ||
// .catch(error => { | ||
// console.error("Error:", error); | ||
// }); | ||
// } | ||
// } |