From a53c57c039e60cc3803d489d8dfbf7b715f5e5cf Mon Sep 17 00:00:00 2001 From: Arthur Lefebvre Date: Tue, 3 Mar 2026 19:04:41 +0100 Subject: [PATCH] Disconnect the user on the frontend when the jwt token is no longer correct --- front/src/AppNavBar.vue | 2 +- front/src/api.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/front/src/AppNavBar.vue b/front/src/AppNavBar.vue index 0bc1a3d..8496392 100644 --- a/front/src/AppNavBar.vue +++ b/front/src/AppNavBar.vue @@ -21,7 +21,7 @@ const appInfo = ref(null); const appInfoErr = ref(null); - async function logInIfDemoMode(demoMode, demoUsername) { + async function logInIfDemoMode(demoMode, demoUsername) { if (!demoMode) { return; } diff --git a/front/src/api.js b/front/src/api.js index c1babd1..9a34355 100644 --- a/front/src/api.js +++ b/front/src/api.js @@ -28,7 +28,13 @@ function useFetch(data, error, url) { 'Authorization': 'Bearer ' + user.token } }) - .then((res) => res.json()) + .then((res) => { + if (res.status === 401) { + const authStore = useAuthStore(); + authStore.logout(); + } + return res.json(); + }) .then((json) => (data.value = json)) .catch((err) => (error.value = err)); }