Skip to content

Commit

Permalink
added profile js for backend conn
Browse files Browse the repository at this point in the history
  • Loading branch information
NK-Works authored Nov 9, 2024
1 parent 6bdf683 commit 8f41b0e
Showing 1 changed file with 26 additions and 0 deletions.
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);
}
});

0 comments on commit 8f41b0e

Please sign in to comment.