Skip to content

Commit 1a9a76e

Browse files
author
Pooya Parsa
committed
fix(store): return promise in all actions
1 parent b0c3ff4 commit 1a9a76e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/templates/auth.store.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default {
3636
actions: {
3737
<% if (options.token.enabled) { %>
3838
// Update token
39-
updateToken ({ commit }, token) {
39+
async updateToken ({ commit }, token) {
4040
// Update token in store's state
4141
commit('SET_TOKEN', token)
4242

@@ -82,7 +82,7 @@ export default {
8282

8383
<% if (options.token.enabled) { %>
8484
// Fetch Token
85-
fetchToken ({ dispatch }) {
85+
async fetchToken ({ dispatch }) {
8686
let token
8787

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

104104
if (token) {
105-
dispatch('updateToken', token)
105+
await dispatch('updateToken', token)
106106
}
107107
},
108108
<% } %>
109109

110110
// Reset
111-
reset ({ dispatch, commit }) {
111+
async reset ({ dispatch, commit }) {
112112
<% if (options.user.enabled) { %>commit('SET_USER', null)<% } %>
113-
<% if (options.token.enabled) { %>dispatch('updateToken', null)<% } %>
113+
<% if (options.token.enabled) { %>await dispatch('updateToken', null)<% } %>
114114
},
115115

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

123123
<% if (options.token.enabled) { %>
124124
// Fetch and update latest token
125-
dispatch('fetchToken')
125+
await dispatch('fetchToken')
126126

127127
// Skip if there is no token set
128128
if (!state.token) {
@@ -138,7 +138,7 @@ export default {
138138
console.error(e)
139139
<% if (options.user.resetOnFail) { %>
140140
// Reset store
141-
dispatch('reset')
141+
await dispatch('reset')
142142
<% } %>
143143
}
144144
},
@@ -150,7 +150,7 @@ export default {
150150
let data = await (this.$axios || this.app.$axios).$post(endpoint, fields)
151151

152152
<% if (options.token.enabled) { %>
153-
dispatch('updateToken', data['<%= options.token.name %>'])
153+
await dispatch('updateToken', data['<%= options.token.name %>'])
154154
<% } %>
155155

156156
// Fetch authenticated user
@@ -170,7 +170,7 @@ export default {
170170
}
171171

172172
// Reset store
173-
dispatch('reset')
173+
await dispatch('reset')
174174
}
175175
}
176176
}

0 commit comments

Comments
 (0)