Commit 817ac51e authored by TTS Kieu Tuan Anh's avatar TTS Kieu Tuan Anh

get data response

parent e683fb3a
...@@ -48,6 +48,7 @@ export default { ...@@ -48,6 +48,7 @@ export default {
</script> </script>
<script> <script>
const token = localStorage.getItem('bgcolor');
export default { export default {
name: "logout", name: "logout",
data() { data() {
...@@ -64,6 +65,7 @@ export default { ...@@ -64,6 +65,7 @@ export default {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
bearer_token: token,
}), }),
}); });
this.$router.push('/'); this.$router.push('/');
......
...@@ -82,8 +82,8 @@ export default { ...@@ -82,8 +82,8 @@ export default {
}; };
}, },
methods: { methods: {
login() { async login() {
fetch("http://127.0.0.1:8000/api/login", { var resp = await fetch("http://127.0.0.1:8000/api/login", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
...@@ -92,8 +92,20 @@ export default { ...@@ -92,8 +92,20 @@ export default {
email: this.email, email: this.email,
password: this.password, password: this.password,
}), }),
}); }).then((response) => {
return response.json();
if(resp.data.bearer_token){
this.$router.push('home'); this.$router.push('home');
}
});
console.log(resp.data.bearer_token)
// localStorage.setItem('bgcolor', resp.data.bearer_token);
await this.$auth.setToken('local', "Bearer " + resp.data.bearer_token);
await this.$auth.setRefreshToken('local', resp.data.refresh);
await this.$auth.setUserToken(resp.data.access);
}, },
}, },
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment