Skip to content

Commit

Permalink
perf: better authenticated check (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
WDaan committed Apr 17, 2022
1 parent 132b849 commit ce698e3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
@@ -1,6 +1,6 @@
version: '3.6'
services:
qbittorrent:
qbit:
image: linuxserver/qbittorrent:latest
container_name: qbit
environment:
Expand Down
26 changes: 8 additions & 18 deletions src/App.vue
Expand Up @@ -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')
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/services/qbit.js
Expand Up @@ -41,7 +41,8 @@ class Qbit {

async getAuthenticationStatus() {
return this.axios.get('/app/version')
.then(response => response.statusText)
.then(() => true)
.catch(() => false)
}

async logout() {
Expand Down

0 comments on commit ce698e3

Please sign in to comment.