feat(frontend): added pinia, i18n and started login

This commit is contained in:
Marco Cavalli 2025-02-21 14:39:57 +01:00
parent 64c11393c4
commit 0392c0c7cf
14 changed files with 455 additions and 20 deletions

View file

@ -0,0 +1,37 @@
import { createRouter, createWebHistory } from "vue-router";
import { useAuthStore } from "@/stores/auth.store.ts";
const routes = [
{
path: '/',
name: 'Dashboard',
component: () => import('../pages/Backoffice.vue'),
},
{
path: '/login',
name: 'Login',
component: () => import('../pages/Login.vue'),
},
];
const router = createRouter({
history: createWebHistory(),
routes
});
export default router;
/**
* Redirect to login page if unauthenticated
*/
router.beforeEach(async (to) => {
// redirect to login page if not logged in and trying to access a restricted page
const publicPages = ['/login'];
const authRequired = !publicPages.includes(to.path);
const auth = useAuthStore();
if (authRequired && !auth.userData) {
auth.returnUrl = to.fullPath;
return '/login';
}
});