export default defineNuxtRouteMiddleware(async () => {
  const auth = useAuthStore()

  if (!auth.checked) {
    await auth.ensureSession()
  }

  const isAdmin = auth.user?.roles?.includes('ROLE_ADMIN')
  if (!isAdmin) {
    return navigateTo('/')
  }
})
