From 14929847a44ac84ef65ad09a90a817fb5c8f29bc Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sun, 5 Feb 2017 11:05:37 +0100 Subject: [PATCH] refresh token when app start --- src/LessPass.vue | 1 + src/store/actions.js | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/LessPass.vue b/src/LessPass.vue index d86fc9c..19ec6b1 100644 --- a/src/LessPass.vue +++ b/src/LessPass.vue @@ -20,6 +20,7 @@ computed: mapGetters(['version']), created(){ this.$store.dispatch('loadPasswordFirstTime'); + this.$store.dispatch('refreshToken'); } } \ No newline at end of file diff --git a/src/store/actions.js b/src/store/actions.js index 73228d8..3b3b370 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -1,4 +1,5 @@ import Password from '../api/password'; +import User from '../api/user'; import * as types from './mutation-types' @@ -6,6 +7,15 @@ export const loadPasswordFirstTime = ({commit}) => { commit(types.LOAD_PASSWORD_FIRST_TIME); }; +export const refreshToken = ({commit, state}) => { + const token = state.token; + if (token) { + User.requestNewToken({token}, {baseURL: state.baseURL}) + .then(newToken => commit(types.SET_TOKEN, {token: newToken})) + .catch(() => commit(types.LOGOUT)); + } +}; + export const loadPasswordForSite = ({commit}, payload) => { commit(types.LOAD_PASSWORD_FOR_SITE, payload); };