From ce698e38a80fb7ba1dee01251451865df75f68d4 Mon Sep 17 00:00:00 2001 From: Daan Wijns Date: Sun, 17 Apr 2022 15:24:01 +0200 Subject: [PATCH] perf: better authenticated check (#411) --- docker-compose.yml | 2 +- src/App.vue | 26 ++++++++------------------ src/services/qbit.js | 3 ++- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c26d6115a2..a8c2e3e96d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ version: '3.6' services: - qbittorrent: + qbit: image: linuxserver/qbittorrent:latest container_name: qbit environment: diff --git a/src/App.vue b/src/App.vue index 188dcee654..ee25ad453f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -36,30 +36,20 @@ export default { created() { this.$store.commit('SET_APP_VERSION', process.env['APPLICATION_VERSION']) this.$store.commit('SET_LANGUAGE') - const needsAuth = this.needsAuthentication() - if (needsAuth) { - this.checkAuthenticated() - } + this.checkAuthentication() }, methods: { - async needsAuthentication() { - const res = qbit.getAuthenticationStatus() - const forbidden = res === 'Forbidden' - if (forbidden) { - return true - } else { + async checkAuthentication() { + const authenticated = await qbit.getAuthenticationStatus() + if (authenticated) { this.$store.commit('LOGIN', true) this.$store.commit('updateMainData') + + return } - return false - }, - async checkAuthenticated() { - const res = await qbit.login() - const authenticated = res === 'Ok.' - this.$store.commit('LOGIN', authenticated) - this.$store.commit('updateMainData') - if (!authenticated && !this.onLoginPage) return this.$router.push('login') + this.$store.commit('LOGIN', false) + if (!this.onLoginPage) return this.$router.push('login') } } } diff --git a/src/services/qbit.js b/src/services/qbit.js index 9d7a41a66c..00fe0a118a 100644 --- a/src/services/qbit.js +++ b/src/services/qbit.js @@ -41,7 +41,8 @@ class Qbit { async getAuthenticationStatus() { return this.axios.get('/app/version') - .then(response => response.statusText) + .then(() => true) + .catch(() => false) } async logout() {