From 6bdf68380d765c968230825241d01ff20061c83d Mon Sep 17 00:00:00 2001 From: Anneshu Nag <132702983+NK-Works@users.noreply.github.com> Date: Sat, 9 Nov 2024 20:00:54 +0530 Subject: [PATCH 1/2] Update profile.html --- profile.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profile.html b/profile.html index 13f7052..094eb6d 100644 --- a/profile.html +++ b/profile.html @@ -167,7 +167,7 @@

Change Password

}); - + main From 8f41b0e02d33fb697ebcd2713d7e3d846e17ed47 Mon Sep 17 00:00:00 2001 From: Anneshu Nag <132702983+NK-Works@users.noreply.github.com> Date: Sat, 9 Nov 2024 20:01:31 +0530 Subject: [PATCH 2/2] added profile js for backend conn --- profile.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 profile.js diff --git a/profile.js b/profile.js new file mode 100644 index 0000000..66232be --- /dev/null +++ b/profile.js @@ -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); + } +});