Demo, all content is generated
Question

Lovable ate 180 credits trying to fix one login redirect

Solved · 1301 views · asked by mina_j · edited

After login users should go to /dashboard. Instead they bounce back to /login. I asked Lovable to fix it, it says "I've fixed the redirect issue", same bug. Repeat. I've now used 180 credits this month on this ONE bug and I'm scared to type anything.

Sometimes it works on first login and then breaks after refresh. Not sure if that matters.

What I’ve tried

Asked it to "fix the redirect loop" maybe 30 times, asked it to add console logs, tried reverting once but then the dashboard page was gone.

Comment
The "works first time, breaks after refresh" is a big clue. Session isn't being restored before the check runs. pixelpaulo · edited
what does that mean in lovable terms 😅 mina_j · edited
Are you using the Supabase auth that Lovable set up, or something custom? jb_supa · edited
the supabase one mina_j · edited

3 answers

Marked as helpful by the asker
jb_supa · edited

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.

Comment
Pasted your prompt exactly. Fixed in one go. I could cry. 1 credit vs 180 mina_j · edited
The "Do not change any other files" line is gold in Lovable. noor_builds · edited
aisha_m · edited

Also: before a risky prompt, note which version works in the history. Restoring a version is free, 30 more prompts are not.

Comment
rosie_q · edited

Also check Authentication > URL Configuration in Supabase has your published domain as Site URL. I had a similar loop that was only on the live site.

Comment
that was already set but thanks mina_j · edited