29 lines
591 B
TypeScript
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('/')
|
|
}
|
|
})
|