fix: redirect to login when auth expires #607

This commit is contained in:
Daan Wijns 2023-03-05 09:11:58 +01:00
parent 607eb3b3d5
commit 0cc22ae1ea
3 changed files with 27 additions and 25 deletions

View file

@ -4,20 +4,13 @@
<p>The sleekest looking WebUI for qBittorrent made with Vue.js!</p>
</div>
![Vue](https://img.shields.io/badge/Vue-%5E2.7.14-brightgreen)
![qBittorrent](https://img.shields.io/badge/qBittorrent-4.4%2B-brightgreen)
![Vue](https://img.shields.io/badge/Vue-%5E2.7.14-brightgreen) ![qBittorrent](https://img.shields.io/badge/qBittorrent-4.4%2B-brightgreen)
![Vuetify](https://img.shields.io/badge/Vuetify-%5E2.6.10-brightgreen)
![stars](https://img.shields.io/github/stars/WDaan/VueTorrent)
![Forks](https://img.shields.io/github/forks/WDaan/VueTorrent)
![Issues](https://img.shields.io/github/issues/WDaan/VueTorrent)
![Closed](https://img.shields.io/github/issues-closed/WDaan/VueTorrent)
![Closed PR](https://img.shields.io/github/issues-pr-closed/WDaan/VueTorrent)
![Version](https://img.shields.io/github/v/release/wdaan/vuetorrent)
![Test Status](https://img.shields.io/github/actions/workflow/status/wdaan/vuetorrent/test.yml)
![Downloads](https://img.shields.io/github/downloads/WDaan/VueTorrent/total)
![stars](https://img.shields.io/github/stars/WDaan/VueTorrent) ![Forks](https://img.shields.io/github/forks/WDaan/VueTorrent)
![Issues](https://img.shields.io/github/issues/WDaan/VueTorrent) ![Closed](https://img.shields.io/github/issues-closed/WDaan/VueTorrent)
![Closed PR](https://img.shields.io/github/issues-pr-closed/WDaan/VueTorrent) ![Version](https://img.shields.io/github/v/release/wdaan/vuetorrent)
![Test Status](https://img.shields.io/github/actions/workflow/status/wdaan/vuetorrent/test.yml) ![Downloads](https://img.shields.io/github/downloads/WDaan/VueTorrent/total)
## Screenshots

View file

@ -1,4 +1,4 @@
import axios from 'axios'
import axios, { AxiosError } from 'axios'
import type { AxiosInstance } from 'axios'
import type {
ApplicationVersion,
@ -81,7 +81,7 @@ export class QBitApi {
}
async getMainData(rid?: number): Promise<MainDataResponse> {
return this.axios.get('/sync/maindata', { params: { rid } }).then(res => res.data)
return this.axios.get('/sync/maindata', { params: { rid } }).then(res => res.data)
}
async toggleSpeedLimitsMode(): Promise<void> {

View file

@ -5,6 +5,7 @@ import type { ModalTemplate, StoreState } from '@/types/vuetorrent'
import Torrent from '@/models/Torrent'
import type { AppPreferences } from '@/types/qbit/models'
import { Status } from '@/models'
import router from '@/router'
export default {
SET_APP_VERSION(state: StoreState, version: string) {
@ -52,20 +53,28 @@ export default {
state.authenticated = payload
},
updateMainData: async (state: StoreState) => {
const response = await qbit.getMainData(state.rid || undefined)
state.rid = response.rid || undefined
try {
const response = await qbit.getMainData(state.rid || undefined)
state.rid = response.rid || undefined
state.status = new Status(response.server_state)
Tags.update(response)
Graph.shiftValues()
state.status = new Status(response.server_state)
Tags.update(response)
Graph.shiftValues()
// fetch torrent data
state.sort_options.isCustomSortEnabled = Torrent.computedValues.indexOf(state.sort_options.sort) !== -1
const data = await qbit.getTorrents(state.sort_options)
// fetch torrent data
state.sort_options.isCustomSortEnabled = Torrent.computedValues.indexOf(state.sort_options.sort) !== -1
const data = await qbit.getTorrents(state.sort_options)
Trackers.update(data)
Torrents.update(data)
DocumentTitle.update()
Trackers.update(data)
Torrents.update(data)
DocumentTitle.update()
} catch (error: any) {
if(error?.response?.status === 403){
console.error("No longer authtenticated, logging out...")
state.authenticated = false
router.push({ name: 'login' })
}
}
},
FETCH_SETTINGS: async (state: StoreState, settings: AppPreferences) => {
state.settings = settings