Add setToken in VueX and call it from SigninForm
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user