Skip to content

Commit

Permalink
fix(store): return promise in all actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa committed Dec 29, 2017
1 parent b0c3ff4 commit 1a9a76e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/templates/auth.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default {
actions: {
<% if (options.token.enabled) { %>
// Update token
updateToken ({ commit }, token) {
async updateToken ({ commit }, token) {
// Update token in store's state
commit('SET_TOKEN', token)

Expand Down Expand Up @@ -82,7 +82,7 @@ export default {

<% if (options.token.enabled) { %>
// Fetch Token
fetchToken ({ dispatch }) {
async fetchToken ({ dispatch }) {
let token

<% if (options.token.localStorage) { %>
Expand All @@ -102,15 +102,15 @@ export default {
<% } %>

if (token) {
dispatch('updateToken', token)
await dispatch('updateToken', token)
}
},
<% } %>

// Reset
reset ({ dispatch, commit }) {
async reset ({ dispatch, commit }) {
<% if (options.user.enabled) { %>commit('SET_USER', null)<% } %>
<% if (options.token.enabled) { %>dispatch('updateToken', null)<% } %>
<% if (options.token.enabled) { %>await dispatch('updateToken', null)<% } %>
},

<% if (options.user.enabled) { %>
Expand All @@ -122,7 +122,7 @@ export default {

<% if (options.token.enabled) { %>
// Fetch and update latest token
dispatch('fetchToken')
await dispatch('fetchToken')

// Skip if there is no token set
if (!state.token) {
Expand All @@ -138,7 +138,7 @@ export default {
console.error(e)
<% if (options.user.resetOnFail) { %>
// Reset store
dispatch('reset')
await dispatch('reset')
<% } %>
}
},
Expand All @@ -150,7 +150,7 @@ export default {
let data = await (this.$axios || this.app.$axios).$post(endpoint, fields)

<% if (options.token.enabled) { %>
dispatch('updateToken', data['<%= options.token.name %>'])
await dispatch('updateToken', data['<%= options.token.name %>'])
<% } %>

// Fetch authenticated user
Expand All @@ -170,7 +170,7 @@ export default {
}

// Reset store
dispatch('reset')
await dispatch('reset')
}
}
}

0 comments on commit 1a9a76e

Please sign in to comment.