Browse Source

refresh token when app start

pull/342/head
Guillaume Vincent 7 years ago
parent
commit
14929847a4
2 changed files with 11 additions and 0 deletions
  1. +1
    -0
      src/LessPass.vue
  2. +10
    -0
      src/store/actions.js

+ 1
- 0
src/LessPass.vue View File

@@ -20,6 +20,7 @@
computed: mapGetters(['version']), computed: mapGetters(['version']),
created(){ created(){
this.$store.dispatch('loadPasswordFirstTime'); this.$store.dispatch('loadPasswordFirstTime');
this.$store.dispatch('refreshToken');
} }
} }
</script> </script>

+ 10
- 0
src/store/actions.js View File

@@ -1,4 +1,5 @@
import Password from '../api/password'; import Password from '../api/password';
import User from '../api/user';


import * as types from './mutation-types' import * as types from './mutation-types'


@@ -6,6 +7,15 @@ export const loadPasswordFirstTime = ({commit}) => {
commit(types.LOAD_PASSWORD_FIRST_TIME); 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) => { export const loadPasswordForSite = ({commit}, payload) => {
commit(types.LOAD_PASSWORD_FOR_SITE, payload); commit(types.LOAD_PASSWORD_FOR_SITE, payload);
}; };


Loading…
Cancel
Save