Β© 2026 Hedgehog Software, LLC
const checkAuth = async () => { try { const { user: authUser } = await $fetch('/api/auth/me') user.value = authUser return authUser } catch { user.value = null return null } } //And a global middleware auth.global.ts: export default defineNuxtRouteMiddleware(async (to) => { const authStore = useAuthStore() const publicRoutes = ['/login', '/signup'] if (publicRoutes.includes(to.path)) return if (!authStore.user) { try { const user = await authStore.checkAuth() if (!user) return navigateTo('/login') } catch { return navigateTo('/login') } } })