From 128fe1557c9b6a2a2fc8d8aa8b7c0640388654fc Mon Sep 17 00:00:00 2001 From: Filip Borum Poulsen Date: Fri, 28 Apr 2023 09:02:44 +0200 Subject: [PATCH] Only fetch user endpoint when loggedIn state is not true, and update loginstate --- client/src/views/Home.vue | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/client/src/views/Home.vue b/client/src/views/Home.vue index 14f9fed..9fda5ce 100644 --- a/client/src/views/Home.vue +++ b/client/src/views/Home.vue @@ -122,12 +122,17 @@ export default { }, async created() { // this.parseQueryFilters(); - const res = await fetch(`${import.meta.env.VITE_BASE_API_URL}/user`, { - credentials: import.meta.env.DEV ? "include" : undefined - }); - if (res.status === 401 || res.status === 403) { - this.setLoginState(false); - this.$router.push({ path: "/login" }) + if (!this.loggedIn) { + const res = await fetch(`${import.meta.env.VITE_BASE_API_URL}/user`, { + credentials: import.meta.env.DEV ? "include" : undefined + }); + if (res.status === 401 || res.status === 403) { + this.setLoginState(false); + this.$router.push({ path: "/login" }) + } + else if (res.status === 200) { + this.setLoginState(true); + } } }, data() {