route /login managed through vue router

This commit is contained in:
isUnknown 2025-04-30 16:09:24 +02:00
parent 5b3549068b
commit de52c5e6be
4 changed files with 41 additions and 32 deletions

View file

@ -1,9 +1,9 @@
import { createWebHistory, createRouter } from "vue-router";
import routes from "./routes";
import { useApiStore } from "../stores/api";
import { usePageStore } from "../stores/page";
import { useUserStore } from "../stores/user";
import { getActivePinia } from "pinia";
import { createWebHistory, createRouter } from 'vue-router';
import routes from './routes';
import { useApiStore } from '../stores/api';
import { usePageStore } from '../stores/page';
import { useUserStore } from '../stores/user';
import { getActivePinia } from 'pinia';
const router = createRouter({
history: createWebHistory(),
@ -12,10 +12,14 @@ const router = createRouter({
router.beforeEach(async (to, from, next) => {
const pinia = getActivePinia();
const api = useApiStore(pinia);
const pageStore = usePageStore(pinia);
const userStore = useUserStore(pinia);
if (to.path === '/login') next();
if (!userStore.user) next('/login');
const api = useApiStore(pinia);
try {
const res = await api.fetchData(to.path);

View file

@ -13,6 +13,7 @@ const routes = [
component: Home,
},
{
name: 'Login',
path: '/login',
component: Login,
},