Google Login Works in Preview, Breaks on Your Custom Domain? Fix Redirect URIs
Google sign-in works on your Lovable preview, Bolt preview or localhost. You point a custom domain at the app, click Sign in with Google, and get one of these:
Error 400: redirect_uri_mismatch
Or Google shows the consent screen, then dumps you back on the wrong host, or you land signed out on https://yourdomain.com.
This is almost never a bug in your React code. It is a URL allow-list problem split across two places: Google Cloud Console (Authorized redirect URIs and JavaScript origins) and Supabase (Site URL and Redirect URLs). Below is the exact checklist, using only what the official docs say.
Two different “redirect” settings (don’t mix them up)
People mix these up constantly. They are not the same list.
| Where | What you add | Who uses it |
|---|---|---|
| Google Cloud → OAuth client → Authorized redirect URIs | Your Supabase callback, like https://<project-ref>.supabase.co/auth/v1/callback | Google sends the user to Supabase after they approve |
| Google Cloud → OAuth client → Authorized JavaScript origins | Your app origins, like https://yourdomain.com and http://localhost:5173 | Google’s browser SDK checks where the request came from |
| Supabase → Authentication → URL Configuration | Your app Site URL and Redirect URLs | Supabase sends the user back to your app after it finishes |
Supabase’s Google guide says it plainly: under Authorized redirect URIs, add your Supabase project’s callback URL (from the Google provider page in the dashboard), and under Authorized JavaScript origins, add your application’s URL. (Supabase: Sign in with Google)
Your custom domain belongs in Google’s JavaScript origins and in Supabase’s URL Configuration. It does not go in Google’s Authorized redirect URIs for the standard Supabase OAuth flow.
Why preview worked and production doesn’t
When you first set Google up, you usually added:
- JavaScript origin:
http://localhost:5173or your*.lovable.app/ preview URL - Redirect URI:
https://xxxxx.supabase.co/auth/v1/callback
That is enough for preview. After you move to https://yourdomain.com, Google’s client still only trusts the old origins. Google’s help docs say a request from an unregistered JavaScript origin returns origin_mismatch, and a redirect_uri that does not match returns redirect_uri_mismatch. Changes can take 5 minutes to a few hours to apply. (Google: Manage OAuth Clients)
Step 1: Copy the exact Supabase callback URL
- Open your Supabase dashboard → your project.
- Go to Authentication → Providers → Google (or the Google provider page).
- Copy the Callback URL shown there. It looks like:
https://abcdefghijklmnop.supabase.co/auth/v1/callback
That exact string is what belongs in Google’s Authorized redirect URIs. Do not invent a path on your own domain unless you have set up a Supabase custom auth domain and Google already has that new callback listed.
Step 2: Fix Google Cloud Console
- Open the Google Auth Platform / Cloud Console Clients for the same Google Cloud project your Client ID came from.
- Open the Web application OAuth client (the one whose Client ID is in Supabase).
- Under Authorized JavaScript origins, add every origin people actually use to open your app. Origins have no path:
https://yourdomain.com
https://www.yourdomain.com
http://localhost:5173
Add your Lovable / Vercel / Netlify preview origin too if you still test there. Google’s rules: HTTPS required (except localhost), no path, no wildcards. (Google: Manage OAuth Clients)
- Under Authorized redirect URIs, confirm this exact Supabase callback is present:
https://<project-ref>.supabase.co/auth/v1/callback
If you later enable a Supabase custom domain for Auth (for example https://auth.yourdomain.com), add that callback too, for example https://auth.yourdomain.com/auth/v1/callback, and keep the old .supabase.co one until everything works. Supabase recommends a custom auth domain so the consent screen shows a URL related to your brand instead of .supabase.co. (Supabase: Sign in with Google)
- Save. Wait a few minutes before retesting. Google says updates can take up to a few hours.
Step 3: Fix Supabase URL Configuration
Google sends the user to Supabase. Supabase then sends them to your app. That second hop uses Supabase settings, same as magic links and confirmation emails.
- Go to Authentication → URL Configuration.
- Set Site URL to your real production URL:
https://yourdomain.com
- Add Redirect URLs for every place you send users after login:
https://yourdomain.com/**
http://localhost:5173/**
Add your host’s preview pattern if needed. Supabase’s docs: for redirectTo to work, the URL must be on the allow list; otherwise it falls back to the Site URL. (Supabase: Redirect URLs · Wrong redirect URL troubleshooting)
If emails or OAuth still send people to localhost, follow Supabase auth emails redirect to localhost next. Same Site URL / Redirect URLs page.
Step 4: What your code passes as redirectTo
In browser code, prefer the current origin so preview and production both work:
await supabase.auth.signInWithOAuth({
provider: 'google',
options: {
redirectTo: `${window.location.origin}/auth/callback`,
},
})
Hard-coding http://localhost:5173/... or an old Lovable URL is a classic reason production “breaks” after you only fixed Google Console. For PKCE / server-side flows, that redirectTo must still be on Supabase’s Redirect URLs list, and your callback route must exchange the code for a session. (Supabase: Sign in with Google)
Read the error and match the fix
| What you see | Likely cause | Fix |
|---|---|---|
Error 400: redirect_uri_mismatch | Google’s Authorized redirect URIs don’t include the Supabase callback (or your custom auth domain callback) | Step 2 — redirect URIs |
origin_mismatch / blocked client-side Google button | Authorized JavaScript origins missing https://yourdomain.com | Step 2 — JavaScript origins |
| Google works, then you land on localhost or preview | Supabase Site URL / Redirect URLs still point at the old host, or code passes a hard-coded URL | Steps 3 and 4 |
| Works only after a long wait | Google cache of client settings | Wait up to a few hours after saving |
Consent screen shows a random .supabase.co project | Expected without a Supabase custom auth domain | Optional: set up custom domain + branding |
Using Lovable Cloud instead of your own Supabase?
If the app uses Lovable’s built-in backend, the Auth URL settings live under Lovable (More → Cloud or project auth settings), not a Supabase project you own. You still need a Google Cloud OAuth client. Put the callback URL Lovable shows you in Google’s Authorized redirect URIs, and make sure your custom domain is allowed for post-login redirects. For DNS and domain status, see How to Publish a Lovable App on Your Own Custom Domain.
A prompt for your AI tool
Google OAuth works in preview but fails on our custom domain with
redirect_uri_mismatch or users landing on the wrong host. Search the
project for signInWithOAuth, redirectTo, and hard-coded localhost or
preview URLs. Replace hard-coded redirects with
`${window.location.origin}/auth/callback` (or our real SITE_URL on the
server). List every origin and callback URL I must add in Google Cloud
(Authorized JavaScript origins + Authorized redirect URIs for the
Supabase callback) and in Supabase URL Configuration. Don't change
unrelated auth code.
Final test
- Open
https://yourdomain.comin a private window. - Click Sign in with Google.
- Finish the consent screen. You should land on your domain, signed in.
- Sign out and repeat once more.
- If you still use a preview URL, test that too so you did not wipe its origin by mistake.
While you are fixing auth, run the pre-launch security checklist and, if the page is blank instead of failing at Google, the missing environment variables guide.
Official sources used: Supabase: Sign in with Google · Supabase: Redirect URLs · Supabase: Wrong redirect URL troubleshooting · Google: Manage OAuth Clients. Checked October 2026.
Ready to ship without guessing the next fix?
The Ship It Kit puts the prompts, deploy steps and pre-launch checklist in one place for Lovable, Bolt, Cursor and Replit apps. One-time $19. Launch price: $19 $17 until November 14, 2026.