Skip to content

Commit

Permalink
feat(store): resetOnFail option
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa committed Nov 18, 2017
1 parent 23b12d5 commit 55e2397
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
user: {
endpoint: 'auth/user',
propertyName: 'user',
resetOnFail: true
},
login: {
endpoint: 'auth/login',
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = function (moduleOptions) {
user: {
endpoint: 'auth/user',
propertyName: 'user',
resetOnFail: true
},
login: {
endpoint: 'auth/login',
Expand Down
3 changes: 3 additions & 0 deletions lib/templates/auth.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
<% } %>
}
},

Expand Down

0 comments on commit 55e2397

Please sign in to comment.