supabase icon indicating copy to clipboard operation
supabase copied to clipboard

After switching tabs, useSupabaseClient methods stop working and don't return

Open ErwinAI opened this issue 11 months ago • 11 comments

It seems like things stop working if you tab away or come back to the page moments later. Ive tried this both with retrieving from the Supabase db and auth and for both no promise is returned and it essentially gets stuck. Reproduction below is for the signOut (easiest of the two to reproduce).

This makes this module and supabase as a whole unusable for my app and prevents me from going to production.

Version

@nuxtjs/supabase: v1.1.0 (latest) nuxt: v3.7.3 (latest)

Reproduction

const supabase = useSupabaseClient()
const signOut = async () => {
  const user = useSupabaseUser()

  console.log(user) // does log

  console.log(supabase) // does log

  const { error } = await supabase.auth.signOut()
  
  // no code is executed after this

  if(error) {

    console.log(error)

  } else {
    console.log('redirecting..')

    navigateTo('/account/login')
  }
}

This results in two console logs (see code comments):

image

Steps to reproduce

Login and switch tabs (perhaps wait for a bit or tab in/out of browser), then activate signOut function in the code above to sign out and notice that no redirection is happening and no log is shown in the console after the signOut function. It seems as if the promise is never returned?

What is Expected?

That either an error is returned, or a fulfilled promise with error: null as per the documentation so that navigateTo is activated (see code above)

What is actually happening?

The user is NOT logged out (reloading the page and checking the user still returns an authenticated user object) and no promise is returned.

ErwinAI avatar Sep 22 '23 05:09 ErwinAI