Fix `ignoreGuardsForHomeRoute` workaround...
This commit is contained in:
parent
9a3af24f72
commit
7847191d97
|
|
@ -60,7 +60,7 @@ const selectedCourseSessionTitle = computed(() => {
|
||||||
const appointmentsUrl = computed(() => {
|
const appointmentsUrl = computed(() => {
|
||||||
const currentCourseSession = courseSessionsStore.currentCourseSession;
|
const currentCourseSession = courseSessionsStore.currentCourseSession;
|
||||||
if (currentCourseSession) {
|
if (currentCourseSession) {
|
||||||
return `/course/${currentCourseSession.course.slug}/appointments`;
|
return `/course/dashboard/due-dates`;
|
||||||
} else {
|
} else {
|
||||||
return `/appointments`;
|
return `/appointments`;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,10 @@ const loginRequired = (to: RouteLocationNormalized) => {
|
||||||
return !to.meta?.public;
|
return !to.meta?.public;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function handleCurrentCourseSession(to: RouteLocationNormalized) {
|
export async function handleCurrentCourseSession(
|
||||||
|
to: RouteLocationNormalized,
|
||||||
|
options?: { unset?: boolean }
|
||||||
|
) {
|
||||||
// register after login hooks
|
// register after login hooks
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
if (userStore.loggedIn) {
|
if (userStore.loggedIn) {
|
||||||
|
|
@ -59,7 +62,9 @@ export async function handleCurrentCourseSession(to: RouteLocationNormalized) {
|
||||||
if (to.params.courseSlug) {
|
if (to.params.courseSlug) {
|
||||||
courseSessionsStore._currentCourseSlug = to.params.courseSlug as string;
|
courseSessionsStore._currentCourseSlug = to.params.courseSlug as string;
|
||||||
} else {
|
} else {
|
||||||
courseSessionsStore._currentCourseSlug = "";
|
if (options?.unset) {
|
||||||
|
courseSessionsStore._currentCourseSlug = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!courseSessionsStore.loaded) {
|
if (!courseSessionsStore.loaded) {
|
||||||
console.log("handleCurrentCourseSession: loadCourseSessionsData");
|
console.log("handleCurrentCourseSession: loadCourseSessionsData");
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import {
|
||||||
} from "@/router/guards";
|
} from "@/router/guards";
|
||||||
import { addToHistory } from "@/router/history";
|
import { addToHistory } from "@/router/history";
|
||||||
import { onboardingRedirect } from "@/router/onboarding";
|
import { onboardingRedirect } from "@/router/onboarding";
|
||||||
import type { RouteLocationNormalized } from "vue-router";
|
|
||||||
import { createRouter, createWebHistory } from "vue-router";
|
import { createRouter, createWebHistory } from "vue-router";
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
|
|
@ -396,26 +395,14 @@ router.beforeEach(updateLoggedIn);
|
||||||
router.beforeEach(redirectToLoginIfRequired);
|
router.beforeEach(redirectToLoginIfRequired);
|
||||||
|
|
||||||
// register after login hooks
|
// register after login hooks
|
||||||
router.beforeEach(
|
router.beforeEach(async (to, from) => await handleCurrentCourseSession(to));
|
||||||
async (to, from) =>
|
router.beforeEach(async (to, from) => await handleCourseSessionAsQueryParam(to));
|
||||||
await ignoreGuardsForHomeRoute(to, from, handleCurrentCourseSession)
|
|
||||||
);
|
|
||||||
|
|
||||||
router.beforeEach(
|
// only unset the current course session in the after hook
|
||||||
async (to, from) =>
|
router.afterEach(
|
||||||
await ignoreGuardsForHomeRoute(to, from, handleCourseSessionAsQueryParam)
|
async (to, from) => await handleCurrentCourseSession(to, { unset: true })
|
||||||
);
|
);
|
||||||
|
|
||||||
async function ignoreGuardsForHomeRoute(
|
|
||||||
to: RouteLocationNormalized,
|
|
||||||
from: RouteLocationNormalized,
|
|
||||||
guard: any
|
|
||||||
) {
|
|
||||||
if (to.name !== "home") {
|
|
||||||
return await guard(to);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
router.beforeEach(addToHistory);
|
router.beforeEach(addToHistory);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,10 @@ from vbv_lernwelt.course.views import (
|
||||||
from vbv_lernwelt.course_session.views import get_course_session_documents
|
from vbv_lernwelt.course_session.views import get_course_session_documents
|
||||||
from vbv_lernwelt.dashboard.views import (
|
from vbv_lernwelt.dashboard.views import (
|
||||||
get_dashboard_config,
|
get_dashboard_config,
|
||||||
|
get_dashboard_due_dates,
|
||||||
get_dashboard_persons,
|
get_dashboard_persons,
|
||||||
get_mentee_count,
|
get_mentee_count,
|
||||||
get_mentor_open_tasks_count,
|
get_mentor_open_tasks_count,
|
||||||
get_dashboard_due_dates,
|
|
||||||
)
|
)
|
||||||
from vbv_lernwelt.edoniq_test.views import (
|
from vbv_lernwelt.edoniq_test.views import (
|
||||||
export_students,
|
export_students,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue