17 lines
341 B
TypeScript
17 lines
341 B
TypeScript
export default defineNuxtRouteMiddleware(async (to) => {
|
|
const auth = useAuthStore()
|
|
const isLogin = to.path === '/login'
|
|
|
|
if (!auth.checked) {
|
|
await auth.ensureSession()
|
|
}
|
|
|
|
if (!isLogin && !auth.isAuthenticated) {
|
|
return navigateTo('/login')
|
|
}
|
|
|
|
if (isLogin && auth.isAuthenticated) {
|
|
return navigateTo('/')
|
|
}
|
|
})
|