diff --git a/client/src/router/guards.ts b/client/src/router/guards.ts index 074efdfe..52b76999 100644 --- a/client/src/router/guards.ts +++ b/client/src/router/guards.ts @@ -1,13 +1,13 @@ import { useUserStore } from "@/stores/user"; import type { NavigationGuardWithThis, RouteLocationNormalized } from "vue-router"; -export const updateLoggedIn: NavigationGuardWithThis = (_to) => { +export const updateLoggedIn: NavigationGuardWithThis = async (_to) => { const loggedIn = getCookieValue("loginStatus") === "true"; const userStore = useUserStore(); userStore.$patch({ loggedIn }); - if (loggedIn && !userStore.email) { - userStore.fetchUser(); + if (loggedIn && !userStore.id) { + await userStore.fetchUser(); } }; diff --git a/client/src/stores/user.ts b/client/src/stores/user.ts index d269530f..1067c136 100644 --- a/client/src/stores/user.ts +++ b/client/src/stores/user.ts @@ -71,20 +71,14 @@ export const useUserStore = defineStore({ window.location.href = redirectUrl; }); }, - fetchUser() { + async fetchUser() { const appStore = useAppStore(); - itGetCached("/api/core/me/") - .then((data) => { - this.$state = data; - this.loggedIn = true; - appStore.userLoaded = true; - const courseSessionsStore = useCourseSessionsStore(); - courseSessionsStore.loadCourseSessionsData(); - }) - .catch(() => { - this.loggedIn = false; - appStore.userLoaded = true; - }); + const data = await itGetCached("/api/core/me/"); + this.$state = data; + this.loggedIn = true; + appStore.userLoaded = true; + const courseSessionsStore = useCourseSessionsStore(); + await courseSessionsStore.loadCourseSessionsData(); }, }, });