const PUBLIC_PATHS = ["/", "/index", "/login", "/register"]; export default defineNuxtRouteMiddleware(async (to) => { if (PUBLIC_PATHS.includes(to.path)) return; try { const res = await $fetch<{ code: number }>("/api/auth/me"); if (res.code !== 0) { return navigateTo("/login?redirect=" + encodeURIComponent(to.fullPath)); } } catch { return navigateTo("/login?redirect=" + encodeURIComponent(to.fullPath)); } });