i have added this as an issue now https://github.c...
# help
a
i have added this as an issue now https://github.com/supabase/supabase-js/issues/339
@User can someone please help me here this issue hasn’t been acknowledged
j
Is this based on an example app from supabase ?
a
The code to fetch the user is from the docs
d
Hi @User thanks for the issue report! I've responded in the issue here for some more info and perhaps a cause. https://github.com/supabase/supabase-js/issues/339
a
Hey can we jump on a call here in discord, I can explain it all
d
Maybe later as working on something else at the moment, but any info you can add to the issue with help others in Supabase understand it as well and maybe they have an idea
Thanks for understanding
a
sure will do
Ive explained as much as ive understood, just ping me on discord if thers something else you want to ask, my github notifs are a mess
j
Might help more if you could share a larger code example. As David mentioned in the github responses, it's easier to figure out a solution to this if there's more context. Are you running this useEffect in a page, or is it in _app.js / _document.js ? even better, If you can share a full app example it would be super helpful.
a
i ran it in a page, i can share the app im using it in but it would be better if we could jump on a voice channel here so i cud give you all the details
@User https://www.loom.com/share/0ce50ac5f17c4d08b44e732150a61d78 heres a video of whats actually happening
this is in the /home page and this is the code
Copy code
jsx
  useEffect(() => {
    setSession(supabase.auth.session() as any);
    console.log(
      session?.provider_token.toString().substring(0, 6),
      session?.access_token.toString().substring(0, 10),
      "this is the session"
    );
    supabase.auth.onAuthStateChange((_event, session) => {
      setSession(session as any);
      console.log(
        session?.provider_token.toString().substring(0, 6),
        session?.access_token.toString().substring(0, 10),
        "this is the onAuthStateChange session"
      );
      setUser(session?.user != null ? session?.user : {});
      setUserID(
        session?.user != null ? session?.user?.user_metadata?.provider_id : ""
      );
    });
  }, []);
all its meant to do is store the current user in a state variable
j
maybe try ... (assumes that you've already initialized supabase-js as
supabase
)
Copy code
js

  const [session, setSession] = useState(null)
  const [user, setUser] = useState(null)

  useEffect(() => {
    const session = supabase.auth.session()
    setSession(session)
    setUser(session?.user ?? null)
    const { data: authListener } = supabase.auth.onAuthStateChange(async (event, session) => {
      setSession(session)
      setUser(session?.user ?? null)
    })

    return () => {
      authListener.unsubscribe()
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [])
this is based on this UserContext.js in our NextJS Auth example app