Ensure promise chaining works

This commit is contained in:
Björn Fromme
2018-10-16 15:31:02 +02:00
parent 8ea027f782
commit c98e95b7cf
2 changed files with 9 additions and 5 deletions
@@ -44,11 +44,12 @@ export default new Vuex.Store({
}).then((response) => {
sessionStorage.setItem('token', response.data.token);
commit('loginSuccess');
}).catch((error) => {
commit('loginFailure');
throw error;
}).then(() => {
commit('loading', false);
return response.data.token;
}, (error) => {
commit('loginFailure');
commit('loading', false);
throw error;
});
},
logout({ commit }) {
@@ -60,6 +61,7 @@ export default new Vuex.Store({
}).then(() => {
sessionStorage.removeItem('token');
commit('logout');
return true;
});
},
loadCountries ({ commit }) {
@@ -67,6 +69,7 @@ export default new Vuex.Store({
url: '/api/countries',
}).then((response) => {
commit('setCountries', response.data);
return response.data;
})
}
},
@@ -46,8 +46,9 @@
this.$store.dispatch('login', {
email: this.email,
password: this.password
}).then(() => {
}).then((token) => {
this.$router.push({ name: 'address' });
return token;
}).catch(() => {
this.message = 'Der Login ist fehlgeschlagen :(';
}).then(() => {