[WIP] Добавил авторизированного пользователя и отображение его аватара

This commit is contained in:
megavrilinvv
2022-12-14 13:05:23 +03:00
parent dfb97cda9f
commit 09c60c775f
3 changed files with 39 additions and 2 deletions

View File

@@ -54,6 +54,7 @@ export default {
authorized: true,
user: { username: "", password: "" },
redColor: "var(--border-red-color)",
userData: {},
};
},
computed: {
@@ -83,6 +84,30 @@ export default {
localStorage.username = this.user.username;
localStorage.password = this.user.password;
},
auth(token) {
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`, {
headers: {
Authorization: `Bearer ${token}`,
},
})
.then((res) => {
return res.json();
})
.then((data) => {
this.userData = data;
localStorage.setItem("userData", JSON.stringify(this.userData));
});
});
},
login() {
const requestOptions = {
method: "POST",
@@ -103,6 +128,7 @@ export default {
if (token) {
localStorage.setItem("tokenAccess", token.access);
this.$router.push("/");
this.auth(token.access);
} else {
this.$router.push("/login");
}