auth.onAuthStateChanged triggers on tab switch
See original GitHub issueBug report
Describe the bug
auth.onAuthStateChanged triggers on tab switch
To Reproduce
-
Create starter project using this guide https://supabase.com/docs/guides/with-vue-3
-
add lines to src/main.js
import { supabase } from "./supabase";
supabase.auth.onAuthStateChange(console.log);
- run
npm run dev
- open
http://localhost:3000
in browser - open dev console
- Switch to another tab
- Switch back to previous tab
Expected behavior
1 SIGNED_IN event in console
Actuall behaviour
2 SIGNED_IN event in console
Screenshots
https://www.loom.com/share/56993404e5f348d2bb23b68b0ad15096
System information
- OS: macOS
- Browser (if applies) brave
- Version of supabase-js: 1.35.3
- Version of Node.js: 16.14.0
Issue Analytics
- State:
- Created a year ago
- Comments:8
Top Results From Across the Web
Supabase onAuthStateChange() triggers when switching tabs ...
Supabase onAuthStateChange by default triggers every time a tab is switched. To prevent this, when initializing the client, add {multiTab: ...
Read more >Auth | JavaScript SDK | Node.js (client) API reference - Firebase
This will trigger firebase.auth.Auth.onAuthStateChanged and firebase.auth.Auth.onIdTokenChanged listeners like other sign in methods.
Read more >Using Firebase Authentication - FlutterFire
When the current user is signed out. When there is a change in the current user's token. When the following methods provided by...
Read more >useHooks - Easy to understand React Hook recipes
Suggest a change ... Worse yet, if our effect triggered a state change it could cause an endless loop ... Loading.js"; import {...
Read more >Firebase Authentication for Web
All three functions trigger the ```onAuthStateChanged``` observer… so you should be handling successful auth changes in the handler instead ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Could we reopen this? I think we need another event that is being fired when we change tabs. Because
SIGNED_IN
, from my perspective, means that a user just has signed in, or got signed in, and not just the session refreshed due to changed tabs.Maybe it would make sense to have a
SIGNED_IN_REFRESH
or something, that would be fired.I am currently handing the
SIGNED_IN
so that it redirects to the home route of my app, so everytime a user changes between tabs, it’ll redirect them, which is not particularly what a user would want.createClient(supabaseUrl, supabaseKey, { ...otherOptions, multiTab: false })
should disable this behavior. I am not sure it’s been documented (yet), but I found this option inSupabaseClientOptions
and it fixed the issue for me.