Permalink
Browse files

feat(store): resetOnFail option

  • Loading branch information...
pi0 committed Nov 18, 2017
1 parent 23b12d5 commit 55e2397ddf00e5a94a4e5e5687d3198ea73242ba
Showing with 6 additions and 0 deletions.
  1. +2 −0 README.md
  2. +1 −0 lib/module.js
  3. +3 −0 lib/templates/auth.store.js
@@ -28,6 +28,7 @@
user: {
endpoint: 'auth/user',
propertyName: 'user',
resetOnFail: true
},
login: {
endpoint: 'auth/login',
@@ -57,6 +58,7 @@
Sets the global settings for store **fetch** action.
* **endpoint** - Set the URL of the user data endpoint. It can be a relative or absolute path.
* **propertyName** - Set the name of the return object property that contains the user data. If you want the entire object returned, set an empty string.
* **resetOnFail** - Automatically invalidate all tokens if user fetch fails. (Default is `true`)
#### login
Set the global settings for store **login** action.
@@ -7,6 +7,7 @@ module.exports = function (moduleOptions) {
user: {
endpoint: 'auth/user',
propertyName: 'user',
resetOnFail: true
},
login: {
endpoint: 'auth/login',
@@ -128,8 +128,11 @@ export default {
const data = await this.$axios.$get(endpoint)
commit('SET_USER', data<%= options.user.propertyName ? ('[\'' + options.user.propertyName + '\']') : '' %>)
} catch (e) {
console.error(e)
<% if (options.user.resetOnFail) { %>
// Reset store
dispatch('reset')
<% } %>
}
},

0 comments on commit 55e2397

Please sign in to comment.