Files
Inventory_frontend/app/middleware/profile.global.ts
2025-09-18 08:44:38 +02:00

20 lines
673 B
TypeScript

import { useProfileSession } from '#imports'
export default defineNuxtRouteMiddleware(async (to) => {
const { ensureSession, activeProfile } = useProfileSession()
await ensureSession()
const rawPath = to?.path ?? ''
const normalizedPath = rawPath.startsWith('/') ? rawPath : `/${rawPath}`
const fullPath = to?.fullPath ?? normalizedPath
const routeName = typeof to?.name === 'string' ? to.name : ''
const isProfilesRoute =
normalizedPath.startsWith('/profiles') ||
fullPath.startsWith('/profiles') ||
routeName.startsWith('profiles')
if (process.client && !activeProfile.value && !isProfilesRoute) {
return navigateTo('/profiles')
}
})