NuxtN
Nuxt3y ago
roga

Nuxt & Supabase Auth

I've set up working authentication in my Nuxt 3 app. I have an authGuard middleware that I've set up which is super basic:
export default defineNuxtRouteMiddleware((to, _from) => {
  const user = useSupabaseUser();
  if (!user.value) return navigateTo('/login');
});

The thing is, I'm redirecting from '/login' to '/dashboard' but if I auth guard the dashboard, it immediately sends the user back to '/login' because the very first instant when the script runs, there is still no user registered.

How can I make sure that I wait until the Supabase does it's thing, registers that there is a suer, before checking for a user and redirecting if none is found?
Was this page helpful?