Mattyfaz
05/26/2022, 4:45 AMjavascript
export default defineNuxtRouteMiddleware((to, _from) => {
const user = useSupabaseUser()
if (!user.value) {
return navigateTo('/login')
}
})
Then on the /login
page I have the following watching for when the user logs in:
javascript
watchEffect(() => {
if (user.value) {
navigateTo('/');
}
});
This works and I can successfully add auth to my routes.
However if I open a new tab and go directly to a protected route it thinks I am not authenticated, therefore sending me to login page, which then identifies I am logged in and redirects me to the index page.Needle
05/26/2022, 4:45 AMMattyfaz
05/26/2022, 4:47 AM/sites/5
(a route requiring auth) the middleware will navigate me to /login
because it thinks I am not authenticated, then the watchEffect()
function on /login
will detect that I am actually authenticated, therefore navigating me to the index page.
How do I make the middleware/auth correctly acknowledge that I am authenticated on that first load?