feat(frontend): added pinia, i18n and started login
This commit is contained in:
parent
64c11393c4
commit
0392c0c7cf
14 changed files with 455 additions and 20 deletions
37
resources/js/helpers/router.ts
Normal file
37
resources/js/helpers/router.ts
Normal 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';
|
||||
}
|
||||
});
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue