OAuth callback URL not working in prod
appears when:user clicks 'Sign in with Google' in production — Google's error page shows, or the flow redirects to localhost.
OAuth callback URL not working in prod
Everything works locally. In production, the OAuth round-trip fails: either the provider rejects the redirect URI outright, or the flow loops back to localhost because Supabase's Site URL is still pointed there.
OAuth callback URL not working in production almost always means the production redirect URI is not whitelisted in the provider console. Google throws Error 400: redirect_uri_mismatch; GitHub throws redirect_uri MUST match the registered callback URL. Copy the exact URL from the error screen, paste it into Google Cloud → Credentials, set Supabase Site URL to your production domain, and add NEXTAUTH_URL to Vercel. Ten-minute fix.
How do I fix OAuth callback URL not working in prod?
01// 1. Google Cloud Console → Credentials → your OAuth Client02// Authorized redirect URIs03https://<project-ref>.supabase.co/auth/v1/callback04https://yourapp.com/api/auth/callback/google05https://yourapp.com/auth/callback06 07// 2. Supabase Dashboard → Authentication → URL Configuration08Site URL: https://yourapp.com09Redirect URLs: https://yourapp.com/**10 http://localhost:3000/**11 12// 3. Vercel → Settings → Environment Variables (Production)13NEXTAUTH_URL=https://yourapp.com14 15// 4. Client code — dynamic redirectTo, never hard-coded16await supabase.auth.signInWithOAuth({17 provider: 'google',18 options: { redirectTo: `${window.location.origin}/auth/callback` },19});Not a developer? We fix this for you at a fixed price: $299 emergency triage, done in 48 hours or fully refunded. Not sure what else is broken? Send the repo for the $49 audit.
What if the quick fix doesn't work?
01 · Update every OAuth provider independently
Google, GitHub, and Apple maintain separate allowlists. A fix in Google Cloud does not affect GitHub. Update each provider console with the same set of production, staging, and localhost URLs.
01Google — Cloud Console → APIs & Services → Credentials → OAuth 2.0 Client IDs02GitHub — Settings → Developer settings → OAuth Apps → your app → Authorization callback URL03Apple — developer.apple.com → Certificates, IDs & Profiles → Services IDs → Return URLs02 · Strip trailing slashes and normalize www vs apex
Providers do byte-equal string matching. https://yourapp.com and https://www.yourapp.com are different origins. Pick a canonical host, redirect the other, and add only the canonical version to each provider.
03 · Fix NEXTAUTH_URL on Vercel (Auth.js specific)
Auth.js builds its callback URL from NEXTAUTH_URL. Without it, Auth.js infers the URL from incoming request headers, which on Vercel includes the internal edge runtime hostname, not your public domain. The symptom looks like a provider mismatch but the cause is an environment variable.
04 · Search the repo for hard-coded localhost URLs
Generators hard-code redirectTo: 'http://localhost:3000' in the first OAuth scaffold. Every other fix holds until this string ships to production — then the flow breaks silently because the redirect_uri sent to the provider is literally localhost.
01# Run pre-deploy — block any commit that hard-codes localhost OAuth redirects02grep -rn "redirectTo:.*localhost" src/ && {03 echo "hard-coded OAuth redirect found — use window.location.origin"04 exit 105}The field is called something different in every console
Most people arrive here holding a provider’s error dialog and a phrase from it, and the phrase is the fastest route to the right settings page. Every provider stores the same thing — the list of destinations it will return an authenticated user to — and every one of them labels it differently and enforces a different matching rule. Find your provider’s row and go straight to that field:
| Provider | What the field is called | Where it lives | The matching rule it enforces |
|---|---|---|---|
| Auth0 | Allowed Callback URLs | Application → Settings | Allow-list. “Set of URLs to which Auth0 is allowed to redirect users after they authenticate.” Auth0 also says: “Do not use wildcard placeholders or localhost URLs in your application callbacks or allowed origins fields.” |
| Supabase | Redirect URLs — plus a separate Site URL | Authentication → URL Configuration | Allow-list, wildcards permitted: “Supabase allows you to specify wildcards when adding redirect URLs to the allow list.” Anything else is refused — “Supabase Auth will reject messages that are signed for URLs that are not on the allowed list.” Site URL “defines the default redirect URL when no redirectTo is specified in the code.” |
| Authorized redirect URIs | Cloud Console → APIs & Services → Credentials → OAuth 2.0 Client ID | Exact match, whole string: “The value must exactly match one of the authorized redirect URIs for the OAuth 2.0 client, which you configured in the API Console.” Failure returns redirect_uri_mismatch. | |
| GitHub | Authorization callback URL | Settings → Developer settings → OAuth Apps → your app | Prefix match, not exact: “the redirect URL’s host (excluding sub-domains) and port must exactly match the callback URL. The redirect URL’s path must reference a subdirectory of the callback URL.” |
| Amazon Cognito | Allowed callback URLs | User pool → App client | Allow-list with format rules: the URL must “be an absolute URI”, “be pre-registered with a client” and “not include a fragment component”. Cognito “requires HTTPS over HTTP except for http://localhost for testing purposes only.” |
| Clerk | No allow-list field exists — forceRedirectUrl and fallbackRedirectUrl | Component props and NEXT_PUBLIC_CLERK_SIGN_IN_FORCE_REDIRECT_URL / _FALLBACK_REDIRECT_URL environment variables | Not a list at all. A force URL: “if provided, this URL will always be redirected to after the user signs in.” A fallback URL applies only “if there’s no redirect_url in the path already.” |
Clerk breaks differently from Auth0, and looking for the wrong thing costs an afternoon
Two incompatible models hide behind the same symptom, and no result on this search says so. Auth0, Google, Cognito and Supabase run an allow-list model: production fails because its URL is absent from a list, the provider refuses before your application code ever runs, and the fix is an entry in a dashboard. Clerk runs a parameter model: there is no dashboard list to add production to, because the destination is a value your app supplies — a prop, or an environment variable that was set once for local development and never re-set for the production environment.
That difference gives you a free diagnostic before you open any console. Ask which half of the round trip failed. A provider error page, shown on the provider’s own domain, before your app loads, means you are in the allow-list model — add the URL. A user who signs in successfully and lands somewhere wrong means you are in the parameter model — the authentication worked and the destination was mis-supplied, so read your environment variables rather than hunting for a list that does not exist. GitHub is a third shape again: it prefix-matches, so a redirect URL that is not registered verbatim still succeeds there while the same string fails on Google.
What “exactly match” means when the URL looks identical
Google’s rule is the whole string, not the meaningful part of it, and that is where a URL that looks correct on screen fails anyway. Compare the value in the console against the value in the error dialog character by character, in this order — these are the four differences that survive a visual check:
- Scheme.
http://andhttps://are different strings. A staging entry copied forward keeps the wrong one. - Trailing slash.
https://yourapp.com/auth/callbackandhttps://yourapp.com/auth/callback/are two different registered URIs on an exact-match provider. - Host form. The apex and the
wwwsubdomain are separate hosts and need separate entries, even when one redirects to the other at the edge. - Case. An exact string comparison is case-sensitive; a capitalised path segment fails against a lowercase registration.
None of this applies uniformly. Supabase accepts wildcards, so one https://yourapp.com/** entry covers every path. Auth0 does not: it tells you plainly not to put wildcard placeholders in the callback field, so each production URL is registered on its own line. Read the rule in your row before you reach for a pattern.
Send your app URL. A senior engineer records a 10-minute teardown.
Free, and fully async — no call to book. A senior engineer walks your app on video: what’s broken, what’s risky, what to fix first. In your inbox within 24 hours. Want the code read line by line instead? Send the repo for the $49 audit.
Why do AI-built apps hit OAuth callback URL not working in prod?
Lovable, Bolt, and v0 scaffold OAuth by calling supabase.auth.signInWithOAuth with a redirectTo pointed at the preview URL. That preview URL is allowlisted in the auto-provisioned Supabase project and sometimes even added to the generator's shared Google OAuth client. Everything works in preview. The moment the app is deployed to a real domain, none of those entries match — the production URL is not in Supabase's allowlist, not in Google's allowlist, and not in the hard-coded redirectTo the generator emitted.
The failure is loud in the browser (the user lands on Google's error page) but silent in logs. Your app never runs because the redirect never returns — Google halts the flow with a 400 before calling back. There is no Vercel function invocation to grep, no Supabase log entry to inspect. Founders often spend an hour searching for a bug in their callback route before realizing the callback route was never reached.
The third layer of pain is NEXTAUTH_URL. Auth.js needs this env var to build its own callback URL; without it, Auth.js infers the URL from the incoming request headers, which on Vercel includes the internal edge runtime hostname, not your public domain. The symptom looks identical to a redirect URI mismatch but the cause is an environment variable — which is why the same fix patterns appear repeatedly: touch every allowlist, touch every environment variable, and make every client-side redirect dynamic.
Which AI builders ship OAuth callback URL not working in prod?
How often each AI builder ships this error and the pattern that produces it.
| Builder | Frequency | Pattern |
|---|---|---|
| Lovable | Very high | Hard-codes redirectTo to Lovable preview URL; production apex never registered. |
| Bolt.new | High | Uses bolt.new sandbox redirect URI; custom-domain URL never propagated. |
| v0 | High | Ships Auth.js without NEXTAUTH_URL; callback URL built from Vercel edge hostname. |
| Cursor | Medium | Writes dynamic redirectTo but forgets to update Supabase Site URL from localhost. |
| Replit | Medium | Leftover replit.dev preview URL in provider allowlist shadows production host. |
| Claude Code | Low | Correct runtime code but missing documentation on which providers to update per deploy. |
| Windsurf | Low | Updates Google but not Supabase — flow bounces back to localhost after provider approves. |
| Base44 | Medium | Custom-domain added in Base44 UI but never synced to Google Cloud or Supabase. |
Related errors we fix
How do I stop OAuth callback URL not working in prod recurring?
- →Derive redirectTo from window.location.origin (browser) or NEXTAUTH_URL (server).
- →Keep one canonical host (apex or www) and redirect the other at the edge.
- →Add CI greps that block any commit containing http://localhost in auth code.
- →Maintain a single source-of-truth list of provider allowlists per environment in the repo.
- →Run a post-deploy scripted incognito sign-in that fails the pipeline on a 400 response.
- →Vault the Google client secret at creation time — since June 2025 the Cloud Console masks it after the creation screen closes, and OAuth clients inactive for 6 months are auto-deleted (restorable for 30 days).
Still stuck with OAuth callback URL not working in prod?
Get OAuth flowing across every environment — we touch all four layers.
- →Provider allowlists, Supabase Site URL, NEXTAUTH_URL, and client code aligned in one pass
- →Verified in an incognito smoke test before handover
- →Shipped with a documented per-environment URI list for your team
OAuth callback URL not working in prod questions
Why does my OAuth callback work on localhost but fail in production?+
What does the error redirect_uri_mismatch actually mean?+
Do I have to update Supabase too, or just the OAuth provider?+
How do I handle OAuth callback URLs for multiple environments?+
How long does fixing an OAuth callback URL take?+
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.
Hyder Shah leads Afterbuild Labs, shipping production rescues for apps built in Lovable, Bolt.new, Cursor, Replit, v0, and Base44. our rescue methodology.
OAuth callback URL not working in prod experts
If this problem keeps coming back, you probably need ongoing expertise in the underlying stack.
Sources
- Supabase — OAuth redirect URLs configuration
- Google — OAuth 2.0 for web server apps
- Auth.js — Deployment & callback URLs
- Google — Usability and safety updates to the Google Auth Platform
- Auth0 — Application settings (Allowed Callback URLs; no wildcard placeholders in the callbacks field)
- Clerk — Customize redirect URLs (forceRedirectUrl vs fallbackRedirectUrl and the NEXT_PUBLIC_CLERK_* environment variables)
- GitHub — Authorizing OAuth apps (host and port must match exactly; the path must reference a subdirectory of the callback URL)
- Amazon Cognito — Application-specific settings with app clients (Allowed callback URLs: absolute URI, pre-registered, no fragment; HTTPS required except http://localhost)