UnbreakMyApp / Fix guides

Lovable app shows a blank screen (or spins forever) after login

Why Lovable + Supabase apps freeze after sign-in, and how to fix the onAuthStateChange deadlock and stuck loading states.

Why it happens

The most common cause is code that waits on another Supabase call inside the supabase.auth.onAuthStateChange listener. In older versions of the supabase-js library this creates a deadlock: the listener holds an internal lock, the database call waits for that same lock, and every Supabase request after it hangs. Your app sits on "loading" forever, or renders nothing.

Supabase documents this: the onAuthStateChange callback should not be an async function that awaits other Supabase calls. Newer supabase-js releases (2.107.0+) removed most of this lock, but many AI-generated apps pin older versions or still use the risky pattern.

Other frequent causes: a loading flag that is never set back to false when an error happens, or the site URL / redirect URLs in Supabase Auth settings not including your published domain, so sign-in bounces back without a session.

How to fix it, step by step

  1. Open your browser DevTools (F12) → Console and Network tabs, then log in. If requests to supabase.co stay "pending" forever, it is almost certainly the deadlock.
  2. Find the file that calls supabase.auth.onAuthStateChange (often AuthContext, AuthProvider or useAuth).
  3. Make the callback a plain (non-async) function that only stores the session. Move any database or profile fetch out of it, wrapped in setTimeout(() => { ... }, 0) so it runs after the listener finishes.
  4. Make sure every code path sets loading to false, including errors (use try/finally).
  5. Update @supabase/supabase-js to the latest 2.x version.
  6. In Supabase → Authentication → URL Configuration, confirm the Site URL and Redirect URLs include your live domain (and preview domain).
  7. Log out, clear site data, and log in again to test.

Paste-ready prompt for Lovable

My app shows a blank screen / infinite loading after login. Please fix the Supabase auth listener:
1. Find every supabase.auth.onAuthStateChange call.
2. Make the callback NON-async. Inside it, only call setSession/setUser with the session.
3. Move any Supabase queries (profiles, roles, etc.) out of the callback into setTimeout(() => { ... }, 0) or a separate useEffect that depends on the user id.
4. Ensure the loading state is set to false in a finally block on every path, including errors.
5. Upgrade @supabase/supabase-js to the latest 2.x version.
Do not change any other features. Show me the diff before applying.

FAQ

Why does it only break sometimes?

The deadlock happens on specific auth events (like a token refresh or sign-in), so it can look random. It often appears after the app has been open for a while.

Will setTimeout really fix it?

Yes for the deadlock case. It lets the auth listener finish and release its lock before your query runs. This is the workaround Supabase itself recommends.

Still broken?

Get a free diagnosis by email within 24 hours. Fixed or refunded.

Get a free diagnosis

Or join the waitlist for updates:

Sources