refactor: constanten redirect vervangen door enum

This commit is contained in:
Gabriellvl 2025-05-15 19:33:48 +02:00
parent 4600e5dd9e
commit 064897acd5
3 changed files with 22 additions and 6 deletions

View file

@ -14,6 +14,7 @@ import UserHomePage from "@/views/homepage/UserHomePage.vue";
import SingleTheme from "@/views/SingleTheme.vue";
import LearningObjectView from "@/views/learning-paths/learning-object/LearningObjectView.vue";
import authService from "@/services/auth/auth-service";
import {allowRedirect, Redirect} from "@/utils/redirect.ts";
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
@ -144,10 +145,10 @@ router.beforeEach(async (to, _from, next) => {
if (to.meta.requiresAuth) {
if (!authService.isLoggedIn.value && !(await authService.loadUser())) {
const path = to.fullPath;
if (path !== "/") {
localStorage.setItem("redirectAfterLogin", path);
if (allowRedirect(path)) {
localStorage.setItem(Redirect.AFTER_LOGIN_KEY, path);
}
next("/login");
next(Redirect.LOGIN);
} else {
next();
}