From 8fc10dc17741fa9713604cc8846032104edf11cb Mon Sep 17 00:00:00 2001 From: jasper Date: Mon, 1 Apr 2019 10:46:30 -0700 Subject: [PATCH 1/2] Add Promise.all to send requests when loading --- src/boot/after_store.js | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index f5add8ad..8db1c39d 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -219,6 +219,15 @@ const getNodeInfo = async ({ store }) => { } } +const setConfig = async ({ store }) => { + // apiConfig, staticConfig + const configInfos = await Promise.all([getStatusnetConfig({ store }), getStaticConfig()]) + const apiConfig = configInfos[0] + const staticConfig = configInfos[1] + + await setSettings({ store, apiConfig, staticConfig }) +} + const afterStoreSetup = async ({ store, i18n }) => { if (store.state.config.customTheme) { // This is a hack to deal with async loading of config.json and themes @@ -230,18 +239,26 @@ const afterStoreSetup = async ({ store, i18n }) => { }) } - const apiConfig = await getStatusnetConfig({ store }) - const staticConfig = await getStaticConfig() - await setSettings({ store, apiConfig, staticConfig }) - await getTOS({ store }) - await getInstancePanel({ store }) - await getStaticEmoji({ store }) - await getCustomEmoji({ store }) - await getNodeInfo({ store }) - - // Now we have the server settings and can try logging in + // Now we can try getting the server settings and logging in if (store.state.oauth.token) { - await store.dispatch('loginUser', store.state.oauth.token) + await Promise.all([ + setConfig({ store }), + getTOS({ store }), + getInstancePanel({ store }), + getStaticEmoji({ store }), + getCustomEmoji({ store }), + getNodeInfo({ store }), + store.dispatch('loginUser', store.state.oauth.token) + ]) + } else { + await Promise.all([ + setConfig({ store }), + getTOS({ store }), + getInstancePanel({ store }), + getStaticEmoji({ store }), + getCustomEmoji({ store }), + getNodeInfo({ store }) + ]) } const router = new VueRouter({ From 90939f198b896c0644864f65a430e44e8d3a259c Mon Sep 17 00:00:00 2001 From: jasper Date: Mon, 1 Apr 2019 12:32:13 -0700 Subject: [PATCH 2/2] Fix login handling --- src/boot/after_store.js | 42 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 8db1c39d..fca750ae 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -228,6 +228,19 @@ const setConfig = async ({ store }) => { await setSettings({ store, apiConfig, staticConfig }) } +const checkOAuthToken = async ({ store }) => { + return new Promise(async (resolve, reject) => { + if (store.state.oauth.token) { + try { + await store.dispatch('loginUser', store.state.oauth.token) + } catch (e) { + console.log(e) + } + } + resolve() + }) +} + const afterStoreSetup = async ({ store, i18n }) => { if (store.state.config.customTheme) { // This is a hack to deal with async loading of config.json and themes @@ -240,26 +253,15 @@ const afterStoreSetup = async ({ store, i18n }) => { } // Now we can try getting the server settings and logging in - if (store.state.oauth.token) { - await Promise.all([ - setConfig({ store }), - getTOS({ store }), - getInstancePanel({ store }), - getStaticEmoji({ store }), - getCustomEmoji({ store }), - getNodeInfo({ store }), - store.dispatch('loginUser', store.state.oauth.token) - ]) - } else { - await Promise.all([ - setConfig({ store }), - getTOS({ store }), - getInstancePanel({ store }), - getStaticEmoji({ store }), - getCustomEmoji({ store }), - getNodeInfo({ store }) - ]) - } + await Promise.all([ + checkOAuthToken({ store }), + setConfig({ store }), + getTOS({ store }), + getInstancePanel({ store }), + getStaticEmoji({ store }), + getCustomEmoji({ store }), + getNodeInfo({ store }) + ]) const router = new VueRouter({ mode: 'history',