-
-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
onAuthStateChange fires every time we focus the tab #579
Comments
I have the same issue using Nuxt Supabase. The problem is still present when switching from Nuxt Supabase to @supabase/supabase-js |
My bad, mentioned the wrong issue, ignore the above |
@altryne Could you please share the code in your app that registers the |
Hey @hf (Stojan) The above example replicates my experiene, every time I switch to the tab and back from it, I get a session request sent in network tab |
Hey, would it be possible to take a look at why this is happening? This could add an un-nessesary load on supabase if it's a bug, which seems like it is. I think this is racking up a bunch of un-nessesary calls and is messing up with my code |
Hello @altryne, this is happening because of the Note though, as any other downstream As the original patch was targeting React Native, I believe this extra notification is to get the |
Hey I'm thinking of transferring this issue to nuxt-modules/supabase because this feels like a two-part issue to me:
|
Can't transfer there, so a duplicate is open there. Investigating the event issue now. |
Thank you @hf this seems to me that it does way way too many auth calls to Supa and I could potentially reduce a bunch of load! |
I'm seeing this bug with SvelteKit, so it's not specific to Nuxt |
From what I could find so far, |
I think this fix should address the issue, though I'd like to think more about backward compatibility. |
It would be fantastic to see this PR merged soon. I'm encountering the same issue in a React application. In React, it's a common practice to store the session object in the component state. Because of that, each time a SIGNED_IN event fires and updates the session, it triggers a re-render of the entire application, impacting performance. As a workaround, I'm currently comparing the token field of the incoming and existing session objects before updating the state. While this approach mitigates the issue, it feels more like a patch than a proper solution. Addressing this behavior directly within the Supabase library would be a much cleaner and more efficient way to handle it. |
For anyone stumbling upon this issue, the solution is buried in the Supabase docs: https://supabase.com/docs/guides/getting-started/tutorials/with-sveltekit (src/routes/+layout.svelte) Check if the expiry is the same; if so, discard the event:
|
Bug report
Describe the bug
onAuthStateChange
fires every time we blur (go to a different tab) and focus on the tab with supabaseTo Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
/api/_supabase/session
on every focus eventonAuthStateChange
was fired which triggered the request in nuxtExpected behavior
onAuthStateChange
fires only when the state actually changesScreenshots
System information
Additional context
This doesn't seem to be a nuxt problem as it only subscribes once to the
onAuthStateChange
The text was updated successfully, but these errors were encountered: