From 994152b2c3f33c51b9ea2e6abe20889a567fac08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20A=2E=20Ram=C3=ADrez?= Date: Thu, 28 Dec 2017 11:07:33 -0600 Subject: [PATCH] feat: allow customizing http method for user endpoint (#28) --- README.md | 4 +++- lib/module.js | 3 ++- lib/templates/auth.store.js | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 34dae0eda..3f4bc2d5f 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,8 @@ endpoint: 'auth/user', propertyName: 'user', resetOnFail: true, - enabled: true + enabled: true, + method: 'GET', }, login: { endpoint: 'auth/login', @@ -60,6 +61,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`) +* **method** - Set the request to POST or GET. #### login Set the global settings for store **login** action. diff --git a/lib/module.js b/lib/module.js index 8d03e5782..30d6e9965 100644 --- a/lib/module.js +++ b/lib/module.js @@ -8,7 +8,8 @@ module.exports = function (moduleOptions) { endpoint: 'auth/user', propertyName: 'user', resetOnFail: true, - enabled: true + enabled: true, + method: 'GET' }, login: { endpoint: 'auth/login', diff --git a/lib/templates/auth.store.js b/lib/templates/auth.store.js index e44f17e93..a1e7d1941 100644 --- a/lib/templates/auth.store.js +++ b/lib/templates/auth.store.js @@ -128,7 +128,7 @@ export default { // Try to get user profile try { - const data = await this.$axios.$get(endpoint) + const data = await this.$axios.$<%= options.user.method.toLowerCase() %>(endpoint) commit('SET_USER', data<%= options.user.propertyName ? ('[\'' + options.user.propertyName + '\']') : '' %>) } catch (e) { console.error(e)