I want to guard a route by checking if the user is logged in, but:
- I can't read the composable value,
- I am unsure if my middleware got the right body.
My composable:
// composable/useAuth.js
const useAuth = () => {
// user login, sign out, sign up logic
const isLoggedIn = () => {
return !!user.value
}
return {
isLoggedIn
}
}
export default useAuth
My middleware:
// middleware/check-admin.js
export default defineNuxtRouteMiddleware((to, from) => {
const { isLoggedIn } = useAuth()
console.log(isLoggedIn); // <- Screenshot
if (isLoggedIn) {
return navigateTo(`/albums/${to.params.id}/edit`)
} else {
return navigateTo('/')
}
})
My console logs a method body. But I expected a falsy or truthy value:

Problems:
- How can I read a boolean value from my composables to pass the test inside the middleware?
- It is okay to use
navigateToto abort the routing, if the user got no credentials? The docs says, I can useabortNavigation()