45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
async function loadUser() {
|
|
try {
|
|
const token = getToken();
|
|
const response = await fetch("http://localhost:8000/me", {
|
|
method: "GET",
|
|
headers: {
|
|
"Authorization": `Bearer ${token}`
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error("Unauthorized");
|
|
}
|
|
|
|
const data = await response.json();
|
|
console.log("User info:", data);
|
|
show_data(data)
|
|
} catch (err) {
|
|
showError(["Connection error"]);
|
|
}
|
|
|
|
}
|
|
loadUser();
|
|
function show_data(data) {
|
|
const emailElem = document.getElementById('Account_Email');
|
|
if (emailElem) {
|
|
emailElem.textContent = data.email;
|
|
}
|
|
|
|
const descElem = document.getElementById('Account_Description');
|
|
if (descElem) {
|
|
descElem.textContent = data.description || "—";
|
|
}
|
|
|
|
const activatedElem = document.getElementById('Account_Activated');
|
|
if (activatedElem) {
|
|
activatedElem.textContent = `Active: ${data.activated ? "Yes" : "No"}`;
|
|
}
|
|
|
|
const createdElem = document.getElementById('Account_Created');
|
|
if (createdElem) {
|
|
// красиво обрезать дату
|
|
createdElem.textContent = new Date(data.created_at).toLocaleString();
|
|
}
|
|
} |