updated engine to fetch userinfo if not present
This commit is contained in:
parent
97b11d31d5
commit
5754b74fb2
@ -35,23 +35,20 @@
|
|||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
user: {},
|
|
||||||
authCode: '',
|
authCode: '',
|
||||||
errorMessage: '',
|
errorMessage: '',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async fetch() {
|
async fetch() {
|
||||||
try {
|
this.$engine.fetchUserInfo()
|
||||||
this.user = await this.$axios.$get('/api/userinfo')
|
|
||||||
this.$store.commit('engine/setUser', this.user)
|
|
||||||
} catch(e) {
|
|
||||||
// nop
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
loginDisabled() {
|
loginDisabled() {
|
||||||
return this.authCode.length < 6
|
return this.authCode.length < 6
|
||||||
},
|
},
|
||||||
|
user() {
|
||||||
|
return this.$store.state.engine.user
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async login(e) {
|
async login(e) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<pre class="json">{{ user }}</pre>
|
<pre class="json">{{ userJson }}</pre>
|
||||||
<pre class="json">{{ json }}</pre>
|
<pre class="json">{{ engineJson }}</pre>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -11,10 +11,10 @@ export default {
|
|||||||
await this.$engine.start()
|
await this.$engine.start()
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
json() {
|
engineJson() {
|
||||||
return JSON.stringify(this.$store.state.engine.json, null, 2)
|
return JSON.stringify(this.$store.state.engine.json, null, 2)
|
||||||
},
|
},
|
||||||
user() {
|
userJson() {
|
||||||
return JSON.stringify(this.$store.state.engine.user, null, 2)
|
return JSON.stringify(this.$store.state.engine.user, null, 2)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,9 @@ export default (context, inject) => {
|
|||||||
lastFetched: [0, 0, 0, 0, 0],
|
lastFetched: [0, 0, 0, 0, 0],
|
||||||
async start() {
|
async start() {
|
||||||
if (!store.state.engine.user) {
|
if (!store.state.engine.user) {
|
||||||
window.location.href = "/"
|
if (!await this.fetchUserInfo()) {
|
||||||
|
window.location.href = "/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.fetchUpdate()
|
this.fetchUpdate()
|
||||||
},
|
},
|
||||||
@ -21,8 +23,6 @@ export default (context, inject) => {
|
|||||||
g: store.state.engine.user?.game,
|
g: store.state.engine.user?.game,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
console.log(`url: ${url}`)
|
|
||||||
|
|
||||||
const response = await $axios.get(url)
|
const response = await $axios.get(url)
|
||||||
const json = response.data
|
const json = response.data
|
||||||
store.commit('engine/setJson', json)
|
store.commit('engine/setJson', json)
|
||||||
@ -48,6 +48,17 @@ export default (context, inject) => {
|
|||||||
}, delay)
|
}, 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)
|
inject('engine', engine)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user