From 5754b74fb23928f0ab9a07865af6a951571cb587 Mon Sep 17 00:00:00 2001 From: Settel Date: Thu, 5 Aug 2021 02:33:47 +0200 Subject: [PATCH] updated engine to fetch userinfo if not present --- client/src/components/PlayButton.vue | 11 ++++------- client/src/pages/play.vue | 8 ++++---- client/src/plugins/engine.js | 17 ++++++++++++++--- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/client/src/components/PlayButton.vue b/client/src/components/PlayButton.vue index 537e1cf..78bfdfb 100644 --- a/client/src/components/PlayButton.vue +++ b/client/src/components/PlayButton.vue @@ -35,23 +35,20 @@ export default { data() { return { - user: {}, authCode: '', errorMessage: '', } }, async fetch() { - try { - this.user = await this.$axios.$get('/api/userinfo') - this.$store.commit('engine/setUser', this.user) - } catch(e) { - // nop - } + this.$engine.fetchUserInfo() }, computed: { loginDisabled() { return this.authCode.length < 6 }, + user() { + return this.$store.state.engine.user + }, }, methods: { async login(e) { diff --git a/client/src/pages/play.vue b/client/src/pages/play.vue index 060b1ba..a41084f 100644 --- a/client/src/pages/play.vue +++ b/client/src/pages/play.vue @@ -1,7 +1,7 @@ @@ -11,10 +11,10 @@ export default { await this.$engine.start() }, computed: { - json() { + engineJson() { return JSON.stringify(this.$store.state.engine.json, null, 2) }, - user() { + userJson() { return JSON.stringify(this.$store.state.engine.user, null, 2) }, } diff --git a/client/src/plugins/engine.js b/client/src/plugins/engine.js index f2aa9bc..54c7dee 100644 --- a/client/src/plugins/engine.js +++ b/client/src/plugins/engine.js @@ -7,7 +7,9 @@ export default (context, inject) => { lastFetched: [0, 0, 0, 0, 0], async start() { if (!store.state.engine.user) { - window.location.href = "/" + if (!await this.fetchUserInfo()) { + window.location.href = "/" + } } this.fetchUpdate() }, @@ -21,8 +23,6 @@ export default (context, inject) => { g: store.state.engine.user?.game, }, }) - console.log(`url: ${url}`) - const response = await $axios.get(url) const json = response.data store.commit('engine/setJson', json) @@ -48,6 +48,17 @@ export default (context, inject) => { }, delay) }, + async fetchUserInfo() { + try { + const user = await $axios.$get('/api/userinfo') + store.commit('engine/setUser', user) + } catch(e) { + store.commit('engine/setUser', undefined) + return false + } + + return true + }, } inject('engine', engine) }