Добавил подтягивание аватара юзера

This commit is contained in:
megavrilinvv
2022-12-15 12:09:07 +03:00
parent 28a0d3c210
commit 506ffbfd9d
2 changed files with 22 additions and 28 deletions

View File

@@ -23,9 +23,9 @@
button.header-buttons.flex.justify-center.items-center.mr-8.p-0
.icon-bell.text-xxl
.flex.justify-centflexer.items-center.relative
//- base-avatar.mr-2(:size="36", :color="userData.color", v-if="!userData.photo") {{changeName}}
//- base-avatar.mr-2(:size="32", v-else)
//- img.h-full.object-cover(:src="url + userData.photo", alt="Avatar")
base-avatar.mr-2(:size="36", :color="userData?.color", v-if="!userData?.photo") {{changeName}}
base-avatar.mr-2(:size="32", v-else)
img.h-full.object-cover(:src="url + userData?.photo", alt="Avatar")
button.header-buttons(@click="openPopup")
.icon-down-arrow.text-xxs.flex.justify-center.items-center.p-0
base-popup.right-2.top-10(
@@ -74,9 +74,9 @@ export default {
},
computed: {
changeName() {
return `${this.userData.last_name || ""} ${
this.userData.first_name || ""
} ${this.userData.patronymic || ""}`;
return `${this.userData?.last_name || ""} ${
this.userData?.first_name || ""
} ${this.userData?.patronymic || ""}`;
},
},
methods: {

View File

@@ -84,29 +84,24 @@ export default {
localStorage.username = this.user.username;
localStorage.password = this.user.password;
},
auth(token) {
fetch("http://45.84.227.122:8080/auth/users/me/", {
async auth(token) {
let res = await fetch("http://45.84.227.122:8080/auth/users/me/", {
headers: {
Authorization: `Bearer ${token}`,
},
})
.then((res) => {
return res.json();
})
.then((data) => {
fetch(`http://45.84.227.122:8080/accounts/users/${data.id}/detail`, {
});
res = await res.json();
let data = await fetch(
`http://45.84.227.122:8080/accounts/users/${res.id}/detail`,
{
headers: {
Authorization: `Bearer ${token}`,
},
})
.then((res) => {
return res.json();
})
.then((data) => {
}
);
data = await data.json();
this.userData = data;
localStorage.setItem("userData", JSON.stringify(this.userData));
});
});
},
login() {
const requestOptions = {
@@ -127,8 +122,7 @@ export default {
.then((token) => {
if (token) {
localStorage.setItem("tokenAccess", token.access);
this.$router.push("/");
this.auth(token.access);
this.auth(token.access).then(() => this.$router.push("/"));
} else {
this.$router.push("/login");
}