Why does my app keep redirecting to login?
Last checked 31 Aug 2026
Short answer
This is almost always a session or route-guard bug: either the auth session isn't persisting, or a protected route checks auth state before it's loaded, so it bounces back to login even when signed in.
Why the redirect loop happens
Lovable Cloud (and connected Supabase projects) use auth tokens stored in the browser to know a user is signed in. A redirect loop to login usually means one of:
- The app checks
sessionoruserbefore Supabase has finished loading it (a race condition on first render). - The session token isn't being persisted (e.g. cookies/local storage blocked, or an incognito/testing quirk).
- Your protected route wrapper redirects on any falsy user state, including the brief "loading" state, instead of waiting.
- The redirect target itself is behind the same guard, so it loops.
How to fix it
- Ask Lovable: "Show me the protected route component and how it checks auth state."
- Confirm it distinguishes three states: loading, signed-in, signed-out — and only redirects once loading is false.
- Check that the login page itself isn't wrapped in the same auth guard.
- Clear cookies/local storage and test a fresh sign-in end to end, then test a hard refresh while logged in.
Add a loading state to my auth check so protected routes wait for the session to finish loading before redirecting to login.
What usually goes wrong
- Testing in an environment that blocks third-party cookies or local storage (some in-app browsers do this).
- Multiple redirect rules stacked (e.g. router-level guard plus a component-level guard) fighting each other.
- Environment/config mismatch after connecting a custom domain — see why-does-my-domain-show-a-404-or-403-error for domain-specific auth issues.
Testing properly
Use a private/incognito window for each test so old sessions don't mask the bug. See how-do-i-test-authentication-properly for a fuller checklist.
Sources
Was this answer helpful?
Related questions
- AnswerHow do I add password reset?Ask Lovable to add a "forgot password" flow — it uses Lovable Cloud's authentication to email a reset link and lets the user set a new password.
- AnswerHow do I add login to Lovable?Ask Lovable to add authentication — it enables Lovable Cloud (if not already on), then generates sign-up/login pages and wires them to email, Google, or other providers.
- AnswerHow do I create admin users?Add a `user_roles` table with an `admin` role, assign it to the specific user's ID, and check that role server-side (in RLS policies and any admin-only functions) rather than trusting a front-end flag.
- AnswerHow do I add Google login?Ask Lovable to add Google sign-in — it can use Lovable's managed Google OAuth for a quick setup, or your own Google Cloud OAuth credentials if you need custom branding or scopes.
You might also need
- GuideHow to Create Protected PagesRestrict routes to signed-in users properly — including the server-side check most AI-generated guards miss.
- GuideHow to Add User Login to a Lovable ProjectSign-up, sign-in, sign-out and sessions — plus the settings people forget that break login on the live site.
- GuideHow to Add User Roles and PermissionsAdmin, editor and member roles done safely — stored separately from user profiles so they cannot be escalated.