Client-side data fetch with RLS

Hello, I'm following the 0.7.0+ Svelte-Kit Auth implementation and I've followed this documentation quite closely: https://supabase.com/docs/guides/auth/auth-helpers/sveltekit#client-side-data-fetching-with-rls

^^ Even though I check for
user
and it is populated, the supabaseClient call will still make my call with my
anon
key and not the user's token.

Thus, every time I refresh the page, all queries return an empty array.

async function loadData() {
  const { data } = await supabaseClient
           .from('test')
           .select('*');
  loadedData = data;
}

$: if ($page.data.session.user) {
  loadData(); // <-- This returns [] on load
}


Unless, I wrap the supabaseClient call in setTimeout(()=>{},0). This feels like a hack and I'm wondering what I'm missing?

$: if ($page.data.session.user) {
  setTimeout(() => loadData(), 1);
  // ^^ -- This works but feels hacky
}


---

I saw someone made a similar post but using nextjs, that post said not only do you have to look for the user, but also isLoadingUser. Looking through the documentation I don't see any mention of that or understand if that's a purely nextjs/react thing?
Convenience helpers for implementing user authentication in SvelteKit.
Was this page helpful?