feat: login
This commit is contained in:
50
web/src/router/index.ts
Normal file
50
web/src/router/index.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { authService } from "@/services/auth";
|
||||
import { createRouter, createWebHistory, type RouteRecordRaw } from "vue-router";
|
||||
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: "/",
|
||||
name: "dashboard",
|
||||
component: () => import("@/views/Dashboard.vue"),
|
||||
},
|
||||
{
|
||||
path: "/keys",
|
||||
name: "keys",
|
||||
component: () => import("@/views/Keys.vue"),
|
||||
},
|
||||
{
|
||||
path: "/logs",
|
||||
name: "logs",
|
||||
component: () => import("@/views/Logs.vue"),
|
||||
},
|
||||
{
|
||||
path: "/settings",
|
||||
name: "settings",
|
||||
component: () => import("@/views/Settings.vue"),
|
||||
},
|
||||
{
|
||||
path: "/login",
|
||||
name: "login",
|
||||
component: () => import("@/views/Login.vue"),
|
||||
},
|
||||
];
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes,
|
||||
});
|
||||
|
||||
router.beforeEach((to, _from, next) => {
|
||||
const loggedIn = authService.isLoggedIn();
|
||||
if (to.path !== "/login" && !loggedIn) {
|
||||
return next({ path: "/login" });
|
||||
}
|
||||
|
||||
if (to.path === "/login" && loggedIn) {
|
||||
return next({ path: "/" });
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
export default router;
|
Reference in New Issue
Block a user