chad/client/app/middleware/01.auth.global.ts
Никита Круглицкий ec67be8aa6
All checks were successful
Deploy / deploy (push) Successful in 4m32s
куча говна
2025-10-20 00:10:13 +06:00

21 lines
416 B
TypeScript

import chadApi from '#shared/chad-api'
export default defineNuxtRouteMiddleware(async (to, from) => {
const { me, setMe } = useAuth()
if (!me.value && !from?.name) {
try {
setMe(await chadApi('/me'))
}
catch {
if (to.meta.auth !== 'guest') {
return navigateTo({ name: 'Login' })
}
}
}
if (me.value && to.meta.auth === 'guest') {
return navigateTo('/')
}
})