diff --git a/README.md b/README.md index c3e711d17..0d0a1cf21 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/module.js b/lib/module.js index b0f8c0f01..b824667be 100644 --- a/lib/module.js +++ b/lib/module.js @@ -7,6 +7,7 @@ module.exports = function (moduleOptions) { user: { endpoint: 'auth/user', propertyName: 'user', + resetOnFail: true }, login: { endpoint: 'auth/login', diff --git a/lib/templates/auth.store.js b/lib/templates/auth.store.js index b5e55821a..f8b7c8b50 100644 --- a/lib/templates/auth.store.js +++ b/lib/templates/auth.store.js @@ -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') + <% } %> } },