Skip to content

Commit

Permalink
Merge pull request #1819 from NK-Works/profilepage
Browse files Browse the repository at this point in the history
Proper Profile Page (Dynamic)
  • Loading branch information
ANSHIKA-26 authored Nov 9, 2024
2 parents 6c5f58a + 8f41b0e commit 17d0226
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
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);
}
});

1 comment on commit 17d0226

@vercel
Copy link

@vercel vercel bot commented on 17d0226 Nov 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.