-
Notifications
You must be signed in to change notification settings - Fork 335
/
profile.js
26 lines (23 loc) · 975 Bytes
/
profile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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);
}
});