Hi, using the nuxt/supabase module and trying to i...
# help
m
Hi, using the nuxt/supabase module and trying to implement auth example as provided in the docs: https://supabase.nuxtjs.org/advanced
Copy code
javascript
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:
Copy code
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.
n
Hello @Mattyfaz! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
m
As an example, if I open a new tab and try to go to
/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?