48 lines
1004 B
TypeScript
48 lines
1004 B
TypeScript
import { createRouter, createWebHistory } from "vue-router";
|
|
import HomeView from "../views/HomeView.vue";
|
|
import { useAuthStore } from "@/stores/auth";
|
|
|
|
const routes = [
|
|
{
|
|
path: "/",
|
|
name: "home",
|
|
component: HomeView,
|
|
},
|
|
{
|
|
path: "/login",
|
|
name: "login",
|
|
component: () => import("../views/LoginView.vue"),
|
|
},
|
|
{
|
|
path: "/register",
|
|
name: "register",
|
|
component: () => import("../views/RegisterView.vue"),
|
|
},
|
|
{
|
|
path: "/account",
|
|
name: "account",
|
|
component: () => import("../views/AccountView.vue"),
|
|
meta: { requiresAuth: true },
|
|
},
|
|
{
|
|
path: "/servers",
|
|
name: "servers",
|
|
component: () => import("../views/ServersView.vue"),
|
|
},
|
|
];
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes,
|
|
});
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
const authStore = useAuthStore();
|
|
if (to.meta.requiresAuth && !authStore.isAuthenticated) {
|
|
next({ name: "login" });
|
|
} else {
|
|
next();
|
|
}
|
|
});
|
|
export default router;
|