diff --git a/src/App.vue b/src/App.vue index 05b94e7174..374c0a3dc9 100644 --- a/src/App.vue +++ b/src/App.vue @@ -49,9 +49,24 @@ export default { }()) }) this.$store.commit('SET_APP_VERSION', process.env['APPLICATION_VERSION']) - this.checkAuthenticated() + const needsAuth = this.needsAuthentication() + if (needsAuth) { + this.checkAuthenticated() + } }, methods: { + async needsAuthentication() { + const res = qbit.getAuthenticationStatus() + const forbidden = res === 'Forbidden' + if (forbidden) { + return true + } else { + this.$store.commit('LOGIN', true) + this.$store.commit('updateMainData') + } + + return false + }, async checkAuthenticated() { const res = await qbit.login() const authenticated = res === 'Ok.' diff --git a/src/services/qbit.js b/src/services/qbit.js index 2c3150e806..9fc9e4c836 100644 --- a/src/services/qbit.js +++ b/src/services/qbit.js @@ -39,6 +39,11 @@ class Qbit { return data } + async getAuthenticationStatus() { + return this.axios.get('/app/version') + .then(response => response.statusText) + } + async logout() { this.axios.post('/auth/logout') }