Home / Fixes / OAuth localhost

Google login works on localhost. Production returns 400.

The generator wrote a localhost redirect because that is where it ran. Google, GitHub, and Supabase will not send a production user back to your laptop.

Symptoms

Why Lovable / Bolt / v0 do this

The first signInWithOAuth that compiles uses whatever origin the preview had. That is http://localhost:5173 (Vite) or http://localhost:3000 (Next). The same string gets pasted into the Google client as the only Authorized redirect URI, and into Supabase → Authentication → URL configuration as Site URL. It is consistent. It is also wrong the moment the app has a public hostname.

The actual fix

You must change three places. Changing only the code is the usual way to stay broken.

1. The code

await supabase.auth.signInWithOAuth({
  provider: 'google',
  options: {
    redirectTo: `${window.location.origin}/auth/callback`,
  },
})

Or an env var you set per environment, e.g. VITE_SITE_URL (this one is allowed to be public). Do not leave a hardcoded localhost string in src/.

2. Supabase

Authentication → URL configuration:

3. Google Cloud (or GitHub)

APIs & Services → Credentials → your OAuth 2.0 Client → Authorized redirect URIs. Add the same production and preview callbacks. For Supabase-hosted OAuth the URI is often https://YOURPROJECT.supabase.co/auth/v1/callback — copy the value Supabase shows under Auth → Providers → Google, do not invent it.

Authorized JavaScript origins get the origins without the path: https://yourdomain.com and the Vercel URL.

Google can take a few minutes to accept a new redirect URI. Testing immediately in the same browser profile also reuses an old session. Use a clean profile, wait, then try again.

How to know you are done

  1. Incognito, production URL, Google login, land on /auth/callback on the same host, session cookie present.
  2. Grep the production bundle for localhost:5173 — it should not appear next to redirect.
  3. Preview deploys still work because you added the *.vercel.app callback, not because Site URL is still localhost.

$49 to run this against your tree

The scanner flags localhost redirect URIs in source. The $297 triage is the dashboard clicking if you do not want to. Email contact@shipready.local.

Start an audit See a sample report