init
This commit is contained in:
@@ -80,7 +80,7 @@ const router = createRouter({
|
||||
],
|
||||
})
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
router.beforeEach(async (to) => {
|
||||
const sessionStore = useSessionStore()
|
||||
const authStore = useAuthStore()
|
||||
if (!sessionStore.isReady) {
|
||||
@@ -93,16 +93,16 @@ router.beforeEach(async (to, from, next) => {
|
||||
|
||||
if (authRequired && !authStore.isAuthenticated) {
|
||||
// Non connecté -> Login
|
||||
next('/auth/login')
|
||||
return '/auth/login'
|
||||
} else if (to.name === 'login' && authStore.isAuthenticated) {
|
||||
// Déjà connecté -> Accueil
|
||||
next('/')
|
||||
return '/'
|
||||
} else if (adminRequired && !authStore.isAdmin) {
|
||||
// Connecté mais pas admin -> Accueil (ou page 403)
|
||||
next('/')
|
||||
} else {
|
||||
next()
|
||||
return '/'
|
||||
}
|
||||
// Retourner true ou ne rien retourner permet de continuer la navigation
|
||||
return true
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user