Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper Profile Page (Dynamic) #1819

Merged
merged 2 commits into from
Nov 9, 2024
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
2 changes: 1 addition & 1 deletion profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ <h2>Change Password</h2>

});
</script>

<script src="profile.js"></script>
main
</body>
</html>
26 changes: 26 additions & 0 deletions profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// profile.js
document.addEventListener("DOMContentLoaded", async () => {
try {
// Fetch user profile data from backend
const response = await fetch("http://localhost:5000/api/users/profile", {
method: "GET",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${localStorage.getItem("authToken")}`, // Use your auth token here
},
});

if (!response.ok) {
throw new Error("Failed to fetch profile data.");
}

// Parse the JSON data
const profileData = await response.json();

// Populate profile data in HTML
document.querySelector(".profile-name").textContent = profileData.username;
document.querySelector(".profile-email").textContent = `Email: ${profileData.email}`;
} catch (error) {
console.error("Error fetching profile data:", error);
}
});
Loading