Supabase issue on Vercel

I deployed my frontend ( React + Vite) and used supabase client btw, after login , when reload the page with F5 keyboard, I can see infinite loading with supabase.getsession() how can I do for this problem?
10 Replies
garyaustin
garyaustin2w ago
Are you saying that getSession is called and does not return or it loops somehow infinitely?
Attempt
AttemptOP2w ago
I think does not return useEffect(() => { // Get initial session const getInitialSession = async () => { try { if (typeof window === 'undefined') return; const { data: { session } } = await supabase.auth.getSession();
if (session?.user) { await loadUserProfile(session.user); } setLoading(false); } catch (error) { console.error('Error getting initial session:', error); } setLoading(false); }; getInitialSession(); // Listen for auth changes const { data: { subscription } } = supabase.auth.onAuthStateChange( async (_, session) => { if (session?.user) { console.log(session);
await loadUserProfile(session.user); } else { setUser(null); } setLoading(false); } ); return () => subscription.unsubscribe(); }, []);
garyaustin
garyaustin2w ago
See the important note here if you are using onAuthStateChange. https://supabase.com/docs/reference/javascript/auth-onauthstatechange
JavaScript: Listen to auth events | Supabase Docs
Supabase API reference for JavaScript: Listen to auth events
garyaustin
garyaustin2w ago
That is likely your issue as you are making a call in the event handler maybe to load from supabase. But it will cause another supabase call to hang.
Attempt
AttemptOP2w ago
Thank you. Btw, It's working on my local , but when deploy on vercel. it's not working I think it's really strange problem
garyaustin
garyaustin2w ago
Could be as it is timing based. So if the requests run differently then it can happen You can't do this:
garyaustin
garyaustin2w ago
No description
Attempt
AttemptOP2w ago
Thanks, do you think this problem is comming from this code?
garyaustin
garyaustin2w ago
Did you read the important note in the link. You can’t do await like that in the event handler. It can cause another Supabase call to deadlock.
Attempt
AttemptOP2w ago
Thank you a lot

Did you find this page helpful?