This commit is contained in:
che
2026-07-25 11:15:39 +05:00
parent 860ba21dd0
commit 0544d41b54
27 changed files with 766 additions and 120 deletions
+33
View File
@@ -0,0 +1,33 @@
import { createRouter, createWebHashHistory } from "vue-router";
import { isAuthenticated, useAuth } from "../../shared/auth/useAuth";
import { loginRoute } from "../../apps/auth/routes";
import { contractsRoutes } from "../../apps/contracts/routes";
import { tasksRoutes } from "../../apps/tasks/routes";
import { usersRoutes } from "../../apps/users/routes";
export const router = createRouter({
history: createWebHashHistory(),
routes: [
{
path: "/",
redirect: "/tasks",
},
...tasksRoutes,
...usersRoutes,
...contractsRoutes,
loginRoute,
],
});
router.beforeEach(async (to) => {
const { restoreToken } = useAuth();
await restoreToken();
if (to.meta.requiresAuth && !isAuthenticated()) {
return { path: "/login", query: { redirect: to.fullPath } };
}
if (to.path === "/login" && isAuthenticated()) {
return "/tasks";
}
});