question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

auth.onAuthStateChanged triggers on tab switch

See original GitHub issue

Bug report

Describe the bug

auth.onAuthStateChanged triggers on tab switch

To Reproduce

  1. Create starter project using this guide https://supabase.com/docs/guides/with-vue-3

  2. add lines to src/main.js

import { supabase } from "./supabase";
supabase.auth.onAuthStateChange(console.log);
  1. run npm run dev
  2. open http://localhost:3000 in browser
  3. open dev console
  4. Switch to another tab
  5. 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:closed
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

6reactions
madebyfabiancommented, Nov 24, 2022

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.

5reactions
OrangeNotecommented, May 14, 2022

createClient(supabaseUrl, supabaseKey, { ...otherOptions, multiTab: false }) should disable this behavior. I am not sure it’s been documented (yet), but I found this option in SupabaseClientOptions and it fixed the issue for me.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found