Add setToken in VueX and call it from SigninForm

This commit is contained in:
Hubert Van De Walle 2020-04-12 17:33:03 +02:00
parent a92a0d1c7e
commit 1363ad489e
2 changed files with 16 additions and 9 deletions

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

View File

@ -4,12 +4,13 @@ import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
},
mutations: {
},
actions: {
},
modules: {
}
state: {
token: ''
},
mutations: {
setToken: (state, {token}) => {
state.token = token;
}
},
actions: {}
})