Files
Ferme/frontend/middleware/auth.global.ts
T
Lethary fa1f0ccaa4
Auto Tag Develop / tag (push) Has been cancelled
feat : add role guest
2026-05-05 15:51:58 +02:00

29 lines
591 B
TypeScript

import { useAuthStore } from '~/stores/auth'
export default defineNuxtRouteMiddleware(async (to) => {
const auth = useAuthStore()
const guestAllowedPaths = [
'/',
'/reception/waiting-reception',
'/reception/finish-reception',
'/shipment/waiting-shipment',
'/shipment/finish-shipment'
]
if (to.path === '/login') {
return
}
if (!auth.isAuthenticated) {
await auth.ensureSession()
}
if (!auth.isAuthenticated) {
return navigateTo('/login')
}
if (auth.isGuest && !guestAllowedPaths.includes(to.path)) {
return navigateTo('/')
}
})