Add setToken in VueX and call it from SigninForm

This commit is contained in:
2020-04-12 17:33:03 +02:00
parent a92a0d1c7e
commit 1363ad489e
2 changed files with 16 additions and 9 deletions
+7 -1
View File
@@ -38,6 +38,7 @@
<script>
import Api from '@/api'
import {mapMutations} from "vuex";
export default {
name: "SignupForm",
@@ -52,6 +53,8 @@
}
},
methods: {
...mapMutations(['setToken']),
signin() {
this.error = false
this.invalid = false
@@ -60,8 +63,11 @@
username: this.form.username,
password: this.form.password
})
.then(response => console.log(response.data))
.then(response => {
this.setToken({token: response.data.token})
})
.catch(error => {
console.log(error)
if (error.response && error.response.status === 401)
this.invalid = true
else