From 1cc0c2ce7660d2a37e31bca81884f1ef409d7ef1 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 18 Aug 2021 17:28:31 +0200 Subject: [PATCH] Removed auth from stats --- src/lib/Apiclient.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/lib/Apiclient.js b/src/lib/Apiclient.js index f5c6827..b8524c8 100644 --- a/src/lib/Apiclient.js +++ b/src/lib/Apiclient.js @@ -1,11 +1,19 @@ import axios from 'axios'; import UserStore from './UserStore'; + +axios.interceptors.response.use(response => { + return response; +}, error => { + if (error.response.status === 401) { + UserStore.logout(); + } + return error; +}); + export default class Apiclient { static async getStats() { return ( - await axios.get('https://kauft.es/api/stats', { - headers: { Authorization: `Bearer ${UserStore.state.token}` } - }) + await axios.get('https://kauft.es/api/stats') ).data; } @@ -50,4 +58,12 @@ export default class Apiclient { }) ).data; } + + static async logout() { + return ( + await axios.post(`https://kauft.es/api/auth/logout`, {}, { + headers: { Authorization: `Bearer ${UserStore.state.token}` } + }) + ).data; + } }