add auth flux

This commit is contained in:
Robin COuret
2026-03-06 17:42:04 +01:00
parent a06e9c3633
commit 34845b9696
7 changed files with 60 additions and 6 deletions
+16
View File
@@ -1,5 +1,8 @@
import { createRouter, createWebHistory } from 'vue-router'
import { isAuthenticated } from '@/services/apiAxios'
const pagesWithoutGuard = ['login', 'app']
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
@@ -7,6 +10,12 @@ const router = createRouter({
path: '/',
alias: '/app',
name: 'app',
component: () => import('@/views/WelcomeView.vue'),
},
{
path: '/experiment',
alias: '/experiment',
name: 'experiment',
component: () => import('@/views/ExperimentView.vue'),
},
{
@@ -18,4 +27,11 @@ const router = createRouter({
],
})
router.beforeEach(async (to, from) => {
const isAuth = await isAuthenticated()
if (!isAuth && !pagesWithoutGuard.includes(to.name!.toString())) {
return { name: 'login' }
}
})
export default router