fix
This commit is contained in:
@@ -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";
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user