afterbuild/ops
ERR-170/stack trace
ERR-170
Lovable login not working after deploy? Auth debugging playbook

Lovable login not working after deploy? Auth debugging playbook

Last updated 15 April 2026 · 8 min read · By Hyder Shah
Direct answer

Lovable login fails in production on one of six layers: env vars not propagated, Site URL wrong, cookies not cross-subdomain, RLS blocks the session query, session never refreshes, or middleware redirects before the session loads. Diagnose top-down. Multi-million-token auth spirals are the public horror stories; yours should take 15 minutes.

Quick fix for Lovable login not working after deploy

Start here

Verify env vars in the production bundle

Deploy a throwaway page that prints import.meta.env.VITE_SUPABASE_URL. If it’s undefined, your host is missing the variable. Add it and redeploy. (Remove the throwaway page after.)

Deeper fixes when the quick fix fails

  1. 02

    Fix Site URL and Redirect URLs

    Supabase → Authentication → URL Configuration. Site URL = https://yourapp.com. Redirects include https://yourapp.com/**. Without this, magic links and OAuth callbacks fail silently.

  2. 03

    Check cookies

    After login, DevTools → Application → Cookies should show sb-<ref>-auth-tokenon your domain. If missing, SameSite or Domain is wrong — usually an API on a different subdomain. Set the cookie Domain=.yourapp.com and SameSite=Lax.

  3. 04

    Confirm RLS lets the user read their own profile

    Most “logged in but app shows logged-out state” bugs are the profiles/users table rejecting the select. Policy: using (auth.uid() = id). Test in the SQL editor logged in as that user.

  4. 05

    Enable session refresh

    createClient(url, key, {
      auth: {
        autoRefreshToken: true,
        persistSession: true,
        detectSessionInUrl: true,
      },
    });
  5. 06

    Order middleware: session first, redirect second

    In Next.js middleware, await the session check before any redirect. Most broken AI-generated middleware redirects before the session resolves, bouncing logged-in users to /login. Use @supabase/ssr and getUser() (which revalidates, unlike getSession).

Why AI-built apps hit Lovable login not working after deploy

Supabase auth on Lovable has more moving parts than it looks. The client writes a cookie, the server reads it, middleware checks it, RLS authorizes queries against it, and the session silently refreshes every hour. Any one of those links breaking produces the same user-visible symptom: “I signed in and nothing happened.”

Industry benchmarks put AI-code vulnerability rates close to half (see our 2026 research), and auth logic inversion is near the top of the list — AI generating if (user) redirect instead of if (!user) redirect is real and we have seen it ship.

After pouring an obscene amount of time and credits, I still don't have a working user registration and login flow.
Reddit — Lovable user

Diagnose Lovable login not working after deploy by failure mode

Walk down each layer. Stop at the first one that fails.

LayerTestIf broken
Env varsconsole.log import.meta.env — are the keys there?Add to prod host, redeploy
Site URLSupabase Auth → URL ConfigurationSet to https://yourapp.com
CookiesDevTools → Application → CookiesSet SameSite=Lax, Domain=.yourapp.com
RLS on profiles tableLog in, then SELECT from profilesAdd auth.uid() = id policy
Session refreshLeave tab open 1 hour, refreshEnable autoRefreshToken: true
MiddlewareCheck auth ordering in middleware.tsAwait session before redirect

Related errors we fix

Still stuck with Lovable login not working after deploy?

Emergency triage · $299 · 48h turnaround
We restore service and write the root-cause report.

If you’re past 4 hours on an auth bug, the next prompt will not fix it.

start the triage →

Lovable login not working after deploy questions

My Lovable login works locally but fails in production. Where do I start?+
Start with env vars and Site URL — together they cause 70% of post-deploy auth failures. In Lovable preview, these are auto-configured. In production, you set them yourself. Deploy a test page that logs import.meta.env and check DevTools for the auth cookie after signing in. Whichever is missing is your first fix.
Why does my Lovable app show 'logged in' and 'logged out' at the same time?+
Usually RLS blocking the profiles/users table read. Auth succeeds (you have a session cookie) but the app can't load your profile row to prove who you are, so the UI falls back to the logged-out state. Add a SELECT policy with using (auth.uid() = id) on profiles. The split-state symptom disappears.
Why does my Lovable login work, then break after an hour?+
Session token expired and your client isn't refreshing. Supabase tokens live 1 hour. If autoRefreshToken is false or the refresh call is going to localhost, users get silently logged out. Set autoRefreshToken: true in the client config and make sure Site URL points to production.
Why does my Lovable middleware bounce logged-in users to the login page?+
The middleware is running before the session cookie has been read. Use @supabase/ssr's createServerClient pattern and await getUser() (not getSession, which doesn't revalidate). If getUser returns a user, skip the redirect. AI-generated middleware often inverts this — redirecting before awaiting — and produces a redirect loop.
How much does it cost to fix broken auth on a Lovable app?+
Our Fix-Broken-Auth service is $799 fixed price with 48-hour turnaround. It covers all six layers above, plus password reset, email verification, session refresh, and a test harness so auth regressions get caught in CI before they reach users.
Next step

Ship the fix. Keep the fix.

Emergency Triage restores service in 48 hours. Break the Fix Loop rebuilds CI so this error cannot ship again.

About the author

Hyder Shah leads Afterbuild Labs, shipping production rescues for apps built in Lovable, Bolt.new, Cursor, Replit, v0, and Base44. our rescue methodology.

Lovable login not working after deploy experts

If this problem keeps coming back, you probably need ongoing expertise in the underlying stack.

Sources