export default defineNuxtRouteMiddleware((to) => { const authentication = useAuth()…
- User
export default defineNuxtRouteMiddleware((to) => { const authentication = useAuth() const isLoggedIn = authentication.isLoggedIn() console.log(isLoggedIn)
if (!isLoggedIn && to.path !== '/') return navigateTo('/') if (isLoggedIn && to.path === '/') return navigateTo('/user') }) this is my auth middleware but when i hit /user from the login page without logging in it still redirects to the user page
- Assistant
It is possible that the
useAuthfunction is not returning the expected value, or that the authentication state is not being properly managed. Here are a few suggestions to troubleshoot the issue:-
Double-check the
useAuthfunction and the authentication logic to verify that it is correctly determining if the user is logged in or not. -
Check that the
authenticatemethod is properly setting the authentication state, and that it is persisted across page reloads. -
Make sure that the authentication state is not being reset or cleared by another part of the application, such as a logout function or a page refresh.
-
If the issue persists, consider adding additional logging or debugging statements to narrow down the cause of the problem.
-