Stop prompting first, you're in a loop where each fix undoes the last one.
What's happening (very likely): your protected route checks user on first render. On refresh, Supabase hasn't loaded the session from storage yet, so user is null for a split second and you get sent to /login.
The fix is to wait for the session to be known:
const [session, setSession] = useState<Session | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
supabase.auth.getSession().then(({ data }) => {
setSession(data.session);
setLoading(false);
});
const { data: sub } = supabase.auth.onAuthStateChange((_e, s) => setSession(s));
return () => sub.subscription.unsubscribe();
}, []);
if (loading) return <Spinner />;
if (!session) return <Navigate to="/login" />;In Lovable, send one precise prompt instead of "fix the redirect": "In the ProtectedRoute component, add a loading state that waits for supabase.auth.getSession() to resolve before deciding to redirect. Do not change any other files."
For credits in general: use chat/plan mode to discuss a bug before letting it edit, and when it's been wrong 3 times in a row, stop and ask a human.