https://supabase.com/ logo
#help
Title
# help
k

kenta37

11/13/2021, 12:05 AM
I'm using onAuthStateChange and when i change auth state it seems like this function runs several times. How can i avoid this?
This is the whole code including client initializing. Could it be that multiple clients gets initialized or something?
g

garyaustin

11/13/2021, 12:27 AM
I believe it all depends on where you are calling useSupabase. If it gets called multiple times I believe you will have multiple listeners.
j

jonny

11/13/2021, 5:31 AM
Yea looks like you’ll end up with a listener every time you use useSupabase() There is an example of using onAuthStateChange using react provider in our NextJS auth example which might be better for this
k

kenta37

11/13/2021, 4:38 PM
Thanks @User I'll look into this!