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
Are you saying that getSession is called and does not return or it loops somehow infinitely?
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(); }, []);
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(); }, []);
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
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.
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
Could be as it is timing based. So if the requests run differently then it can happen
You can't do this:

Thanks, do you think this problem is comming from this code?
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.
Thank you a lot