Fix: Lovable App Stuck in Login Redirect Loop
Quick Answer
The auth check on the dashboard page isn't detecting the authenticated session. Tell Lovable: "Fix the redirect loop. Use supabase.auth.getSession() to check auth state before redirecting. Add a loading state while checking."
Symptoms
- !Page keeps redirecting between /login and /dashboard endlessly
- !Browser shows 'too many redirects' error
- !Login succeeds but immediately redirects back to login
- !URL keeps flashing between two pages
Step-by-Step Fix
Identify the loop
The loop happens when: /dashboard checks auth → not found → redirects to /login → /login checks auth → found → redirects to /dashboard → repeat. The issue is timing — the session hasn't loaded yet when the check runs.
Ask Lovable to add a loading state
Prompt: 'Fix the auth redirect loop. Add a loading state that shows while checking authentication. Only redirect after the auth check completes, not before.'
Check session persistence
If using Supabase Auth, ensure the session is persisted. The default configuration handles this, but custom setups may break persistence.
Clear browser cookies and retry
Sometimes stale auth cookies cause loops. Clear cookies for your app's domain, then try logging in again.
Frequently Asked Questions
The protected page checks auth before the session loads from cookies/storage. It sees 'no session' → redirects to login. Login sees the cookie → redirects to dashboard. Adding a loading state fixes the timing issue.
Check auth asynchronously: const { data: { session } } = await supabase.auth.getSession(). Show a loading spinner while waiting. Only redirect if the check completes and session is null.
Related
Weekly Newsletter
Get next week's fix before you need it.
Join developers getting weekly vibe coding tips, error fixes, and tool updates.
Subscribe on Substack →