diff --git a/package.json b/package.json index f9d92aa..941dc08 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,8 @@ "lodash.debounce": "^4.0.8", "vue": "^2.1.10", "vue-router": "^2.2.0", - "vuex": "^2.1.1" + "vuex": "^2.1.1", + "vuex-persistedstate": "^1.1.0" }, "devDependencies": { "ava": "^0.17.0", diff --git a/src/store/actions.js b/src/store/actions.js index ec5cedd..06ac734 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -8,27 +8,24 @@ const storage = new Storage(); const auth = new Auth(storage); const Passwords = new HTTP('passwords', storage); -export const loadLocalStorage = ({state}) => { - Object.assign({}, state, storage.json()) +export const loadPasswordFirstTime = ({commit}) => { + commit(types.LOAD_PASSWORD_FIRST_TIME); }; export const saveDefaultPassword = ({commit}, payload) => { - storage.save(payload); commit(types.SET_DEFAULT_PASSWORD, payload); }; export const savePassword = ({commit}, payload) => { - storage.save(payload); commit(types.SET_PASSWORD, payload); }; export const saveBaseURL = ({commit}, payload) => { - storage.save(payload); commit(types.SET_BASE_URL, payload); }; export const saveVersion = ({commit}, payload) => { - commit(types.SET_BASE_URL, payload); + commit(types.SET_VERSION, payload); }; export const login = ({commit}) => { diff --git a/src/store/index.js b/src/store/index.js index b6477c6..3de1af5 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -3,33 +3,35 @@ import Vuex from 'vuex' import * as actions from './actions' import * as getters from './getters' import mutations from './mutations' +import createPersistedState from 'vuex-persistedstate'; Vue.use(Vuex); +const defaultPassword = { + login: '', + site: '', + uppercase: true, + lowercase: true, + numbers: true, + symbols: true, + length: 16, + counter: 1, + version: 2 +}; + const state = { authenticated: false, - password: null, + password: defaultPassword, passwords: [], - defaultPassword: { - login: '', - site: '', - uppercase: true, - lowercase: true, - numbers: true, - symbols: true, - length: 16, - counter: 1, - version: 2 - }, - lastUse: new Date().getTime(), + defaultPassword: defaultPassword, + lastUse: null, baseURL: 'https://lesspass.com', }; -actions.loadLocalStorage({state}); - export default new Vuex.Store({ state, getters, actions, mutations, + plugins: [createPersistedState({key: 'lesspass'})] }); \ No newline at end of file