skip to Main Content

I was working on React.js with Supabase SDK.
It was working fine, but I realized that it was not working sometimes.
Actually it didn’t many any requests when I checked Network tab on browser.

console.log("hello");
const { data, error } = await supabase
  .from("stages")
  .select("id, prize_pool, ended_at, created_at")
  .eq("is_active", true)
  .limit(1)
  .single();
console.log("hi");

In above code, I could see hello was printed on console, but hi wasn’t printed. And there was no error and no requests.
I am not sure what’s the problem.

FYI, it was working again when I clear the browser cache.

2

Answers


  1. Chosen as BEST ANSWER
      useEffect(() => {
        const handleAuthChange = async (_event: string, session: any) => {
          const user = session?.user as SupabaseUser | undefined;
          // Original: Calling user profile fetch here
        };
    
        const {
          data: { subscription: authListener },
        } = supabase.auth.onAuthStateChange(handleAuthChange);
    
        return () => authListener.unsubscribe();
      }, []);
    

    Oh, actually I was trying to fetch user profile data from public.users table in the handleAuthChange. I removed it from the handler and implemented it in another useEffect hook, and it was working now. I am not sure why such effect happening. Anyway all supabase Apis were not working when I implemented profile fetch in the handleAuthChange handler.


  2. Please share your full code when you are asking for help with an issue. The supabase docs state that you should not be adding await‘s inside of the onAuthStateChange as this can cause a dead-lock in the function. https://supabase.com/docs/reference/javascript/auth-onauthstatechange

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search