Fix race condition on user loading
This commit is contained in:
parent
15b5223dc5
commit
527b806a35
|
|
@ -1,13 +1,13 @@
|
||||||
import { useUserStore } from "@/stores/user";
|
import { useUserStore } from "@/stores/user";
|
||||||
import type { NavigationGuardWithThis, RouteLocationNormalized } from "vue-router";
|
import type { NavigationGuardWithThis, RouteLocationNormalized } from "vue-router";
|
||||||
|
|
||||||
export const updateLoggedIn: NavigationGuardWithThis<undefined> = (_to) => {
|
export const updateLoggedIn: NavigationGuardWithThis<undefined> = async (_to) => {
|
||||||
const loggedIn = getCookieValue("loginStatus") === "true";
|
const loggedIn = getCookieValue("loginStatus") === "true";
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
|
||||||
userStore.$patch({ loggedIn });
|
userStore.$patch({ loggedIn });
|
||||||
if (loggedIn && !userStore.email) {
|
if (loggedIn && !userStore.id) {
|
||||||
userStore.fetchUser();
|
await userStore.fetchUser();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,20 +71,14 @@ export const useUserStore = defineStore({
|
||||||
window.location.href = redirectUrl;
|
window.location.href = redirectUrl;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
fetchUser() {
|
async fetchUser() {
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
itGetCached("/api/core/me/")
|
const data = await itGetCached("/api/core/me/");
|
||||||
.then((data) => {
|
this.$state = data;
|
||||||
this.$state = data;
|
this.loggedIn = true;
|
||||||
this.loggedIn = true;
|
appStore.userLoaded = true;
|
||||||
appStore.userLoaded = true;
|
const courseSessionsStore = useCourseSessionsStore();
|
||||||
const courseSessionsStore = useCourseSessionsStore();
|
await courseSessionsStore.loadCourseSessionsData();
|
||||||
courseSessionsStore.loadCourseSessionsData();
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
this.loggedIn = false;
|
|
||||||
appStore.userLoaded = true;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue