Lovable + Supabase login loop: the real fix

By Arif Khan, AIVolve LLC · Updated November 20, 2026

Short answer: most login loops in Lovable apps come down to one of four things, so check them in this order. (1) In Supabase, the Site URL and Redirect URLs don't match the address your app actually runs on, so sign-in emails and redirects send people to localhost, the preview or the wrong domain. (2) The app redirects to the login page before Supabase has finished loading the session. (3) People sign in on one address (for example www.) and land on another (the bare domain), and the session doesn't carry over. (4) Sign-in works, but a Row Level Security (RLS) policy blocks the app from reading the user's profile, so the app decides they're "not set up" and sends them back. The fix for each takes minutes once you know which one you have.

Below is how to tell them apart and what to change. You don't need to be a developer for the first and third checks. For the second and fourth, you can paste the prompts into Lovable.

Before you start: which backend are you on?

Lovable apps use one of two setups, and the settings live in different places:

Step 1: Fix the Site URL and Redirect URLs

This is the most common cause, especially when sign-in works in the Lovable preview but fails on the published app or your custom domain.

  1. Set Site URL to the one address you want people to use, exactly as it appears in the browser, including https:// and www. if you use it. For example: https://yourapp.com. Supabase's default is http://localhost:3000, and Supabase notes this setting is critical for email confirmations and password resets.
  2. Under Redirect URLs, add every address your app really runs on:
    • your custom domain (and the www. version if both work)
    • your published lovable.app address
    • your Lovable preview address, if you test sign-in there
  3. Wildcards are allowed for preview addresses (for example https://*.lovable.app/**). For your real domain, list the exact address. Supabase recommends exact URLs in production.

If your app asks Supabase to send people to an address that isn't on this list, Supabase uses the Site URL instead. That's why a wrong Site URL causes so much damage.

Using Google sign-in with your own Google credentials? Your new domain also has to be allowed in Google Cloud Console. The callback Google needs is your Supabase project's https://<project-ref>.supabase.co/auth/v1/callback.

Step 2: Check where the email link points

If the confirmation, magic link or password-reset email opens localhost, an old preview, or a "this site can't be reached" page, the cause is one of these:

Two related symptoms:

Step 3: Make sure the app waits for the session

Some loops happen even when every URL is right. The page loads, the app checks "is anyone signed in?" a split second before Supabase has read the saved session, sees no one, and redirects to /login. Then the login page sees a valid session and redirects back, and it loops.

The fix is a loading state: don't decide where to send the user until Supabase reports its first session state. Ask Lovable:

In the auth provider, add a loading state that starts as true. Set it to false only after supabase.auth.getSession() resolves or onAuthStateChange fires its first event (INITIAL_SESSION). Protected routes should show a spinner while loading is true, and only redirect to /login when loading is false and there's no session. Make sure the onAuthStateChange subscription is created once and unsubscribed on unmount.

A quick test: open the browser's developer console on a protected page, refresh, and watch whether you're sent to /login and then straight back. If so, this is your problem.

Step 4: One domain, not two (session on custom domains)

In a typical Lovable app, Supabase keeps the signed-in session in the browser's storage for that exact address. www.yourapp.com, yourapp.com and yourapp.lovable.app are three separate addresses to the browser, and a session saved on one isn't visible on the others.

So if someone signs in on www.yourapp.com and the redirect or email sends them to yourapp.com, they arrive signed out and get pushed back to login.

The fix:

  1. Pick one address as the real one.
  2. Make your domain provider or host redirect the other version to it (for example www → bare domain, or the reverse).
  3. Make the Supabase Site URL match that one address exactly (Step 1).
  4. Once your custom domain is live, stop sending users to the lovable.app address.

Step 5: Check that RLS lets users read their own profile

This one is sneaky because sign-in actually succeeds. After login, the app reads the user's row from a profiles (or users) table. If Row Level Security is on and there's no policy allowing it, Supabase returns no rows, with no error. The app concludes "this user has no profile" and sends them back to sign-up, onboarding or login.

How to check: in Supabase, open Table Editor → profiles and see whether RLS is enabled and which policies exist. Then ask Lovable:

After login, does the app read from profiles? Show me the RLS policies on that table. A signed-in user must be able to select their own row, where id matches auth.uid(). Also confirm a profile row is created for every new user, and that the code handles 'no row' with maybeSingle() instead of redirecting to login.

The policy Supabase documents for this looks like:

create policy "Users can read their own profile"
on public.profiles
for select
to authenticated
using ( (select auth.uid()) = id );

(Use user_id instead of id if that's how your table links to the user.) Don't "fix" this by turning RLS off. That makes every user's profile readable by anyone with your app's public key.

Also check that a profile row exists at all. Many apps create it with a database trigger when someone signs up. If that trigger fails or was never added, older accounts have no row.

How to confirm it's fixed

  1. In a private browser window, sign up with a new email on your real domain.
  2. Click the email link in that same browser.
  3. Refresh a protected page. You should stay signed in.
  4. Sign out, sign back in, and close and reopen the tab.
  5. Repeat once with a second test account, and check that it can't see the first account's data.

FAQ

Why does login work in the Lovable preview but not on my custom domain?+

Usually because your custom domain isn't in the Supabase Redirect URLs, or the Site URL still points at the preview or lovable.app address. On Lovable Cloud, check More → Users → Settings → Advanced. On your own Supabase project, check Authentication → URL Configuration and add the domain yourself.

Why do my Supabase confirmation emails link to localhost?+

The Site URL is still http://localhost:3000, which is Supabase's default, or your code passes a hard-coded redirect. Set the Site URL to your live domain, use window.location.origin for redirects, and send a new email. Old emails keep the old link.

Can RLS cause a login loop?+

Yes. If RLS is enabled on your profiles table without a policy letting users read their own row, the read returns nothing (no error), and many apps treat that as "not signed in" or "not set up." Add a select policy where auth.uid() matches the row's user ID.

Should I just turn off RLS to make login work?+

No. With RLS off, anyone with your app's public key can read that table. Add the specific policy your app needs instead.

Why does the magic link say it expired the first time I click it?+

Some email security scanners open links before you do, which uses up the one-time link. With the default PKCE flow, the link also has to be opened in the same browser that requested it. A one-time code, or a confirmation page with a button, avoids both.

Still looping?

If you've checked all five and it still loops, the cause is usually something specific to how your app was generated. Our free App X-ray takes about 2 minutes and needs no code or passwords: you paste a prompt into Lovable, send us the report, and get a plain-English verdict on what works, what only looks done and your biggest risk. An AIVolve developer reviews every X-ray within 1 business day. Get a free X-ray →

Related: Supabase RLS for AI-built apps: the 10-minute check · Stripe works in test mode but not live · Supabase "permission denied for table" after Oct 30 · Lovable Cloud vs your own Supabase: what changes for auth · Supabase password reset link expired: the fix

Written by Arif Khan, AIVolve LLC. VibeCoderSOS isn't affiliated with Lovable or Supabase. Settings names were checked against their documentation on October 21, 2026, and may change.

Need help?

Start with a free X-ray: 2 minutes, no code or passwords. You'll get a plain-English verdict on what works, what only looks done, and your biggest risk.

Get a free X-ray →