Files
kestrelos/app/middleware/auth.global.js
Madison Grubb b7046dc0e6 initial commit
2026-02-10 23:32:26 -05:00

11 lines
370 B
JavaScript

const LOGIN_PATH = '/login'
export default defineNuxtRouteMiddleware(async (to) => {
if (to.path === LOGIN_PATH) return
const { user, refresh } = useUser()
await refresh()
if (user.value) return
const redirect = to.fullPath.startsWith('/') ? to.fullPath : `/${to.fullPath}`
return navigateTo({ path: LOGIN_PATH, query: { redirect } }, { replace: true })
})