export default defineNuxtRouteMiddleware(async(to, from) => {
const loggedIn = useState('loggedIn', () => false)
if(loggedIn.value == false) {
if(to.path == '/auth/login') {
await navigateTo(to.path)
}else if(to.path == '/') {
await navigateTo('/auth/login')
}else if(!(to.path == '/auth/login') or !(to.path == '/')) {
//return abortNavigation()
await navigateTo('/auth/login')
}else {
return abortNavigation()
}
}else {
console.log('to:', to.path)
console.log('from:', from.path)
await navigateTo(to.path)
}
})
The problem is "await navigateTo('/auth/login')"
not working of above code in the below lines if I browse to ".../dashboard"
, but work fine when any of the page at least have a "await navigateTo('/dashboard')"
. It work also fine for "return abortNavigation"
---
"else if(!(to.path == '/auth/login') or !(to.path == '/')) {
await navigateTo('/auth/login')
}"
---
But I want without calling first time "await navigateTo('/dashboard')"
from any of the page it should work.