From 9af204b293a9c1b15e472423a4badff505fd662a Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 26 Oct 2018 15:16:23 +0200 Subject: Move login to oauth. --- src/lib/persisted_state.js | 54 ++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'src/lib') diff --git a/src/lib/persisted_state.js b/src/lib/persisted_state.js index 006107e2..002f92b4 100644 --- a/src/lib/persisted_state.js +++ b/src/lib/persisted_state.js @@ -17,7 +17,9 @@ const saveImmedeatelyActions = [ 'clearCurrentUser', 'setCurrentUser', 'setHighlight', - 'setOption' + 'setOption', + 'setClientData', + 'setToken' ] const defaultStorage = (() => { @@ -43,8 +45,8 @@ export default function createPersistedState ({ storage = defaultStorage, subscriber = store => handler => store.subscribe(handler) } = {}) { - return store => { - getState(key, storage).then((savedState) => { + return getState(key, storage).then((savedState) => { + return store => { try { if (typeof savedState === 'object') { // build user cache @@ -67,36 +69,36 @@ export default function createPersistedState ({ value: store.state.config.customTheme }) } - if (store.state.users.lastLoginName) { - store.dispatch('loginUser', {username: store.state.users.lastLoginName, password: 'xxx'}) + if (store.state.oauth.token) { + console.log(store.state.oauth) + store.dispatch('loginUser', store.state.oauth.token) } loaded = true } catch (e) { console.log("Couldn't load state") loaded = true } - }) - - subscriber(store)((mutation, state) => { - try { - if (saveImmedeatelyActions.includes(mutation.type)) { - setState(key, reducer(state, paths), storage) - .then(success => { - if (typeof success !== 'undefined') { + subscriber(store)((mutation, state) => { + try { + if (saveImmedeatelyActions.includes(mutation.type)) { + setState(key, reducer(state, paths), storage) + .then(success => { + if (typeof success !== 'undefined') { + if (mutation.type === 'setOption') { + store.dispatch('settingsSaved', { success }) + } + } + }, error => { if (mutation.type === 'setOption') { - store.dispatch('settingsSaved', { success }) + store.dispatch('settingsSaved', { error }) } - } - }, error => { - if (mutation.type === 'setOption') { - store.dispatch('settingsSaved', { error }) - } - }) + }) + } + } catch (e) { + console.log("Couldn't persist state:") + console.log(e) } - } catch (e) { - console.log("Couldn't persist state:") - console.log(e) - } - }) - } + }) + } + }) } -- cgit v1.2.3-70-g09d2 From 0aa5fe9d0de46b3e5f01860692f0d87132b6f9a4 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 26 Oct 2018 16:05:27 +0200 Subject: Remove gonsole.logg :DD --- src/lib/persisted_state.js | 1 - 1 file changed, 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/persisted_state.js b/src/lib/persisted_state.js index 002f92b4..32fc93c6 100644 --- a/src/lib/persisted_state.js +++ b/src/lib/persisted_state.js @@ -70,7 +70,6 @@ export default function createPersistedState ({ }) } if (store.state.oauth.token) { - console.log(store.state.oauth) store.dispatch('loginUser', store.state.oauth.token) } loaded = true -- cgit v1.2.3-70-g09d2