afterbuild/ops
ERR-302/Google · GitHub · Supabase · Auth.js
ERR-302
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.

Last updated 10 August 2026 · 10 min read · By Hyder Shah
Direct answer

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?

auth/oauth-callback-fix.ts
typescript
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});
Paste provider, Supabase, Vercel, and client updates in order. Redeploy.

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.

providers.md
text
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 URLs

02 · 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.

scripts/check-oauth.sh
bash
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:

ProviderWhat the field is calledWhere it livesThe matching rule it enforces
Auth0Allowed Callback URLsApplication → SettingsAllow-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.”
SupabaseRedirect URLs — plus a separate Site URLAuthentication → URL ConfigurationAllow-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.”
GoogleAuthorized redirect URIsCloud Console → APIs & Services → Credentials → OAuth 2.0 Client IDExact 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.
GitHubAuthorization callback URLSettings → Developer settings → OAuth Apps → your appPrefix 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 CognitoAllowed callback URLsUser pool → App clientAllow-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.”
ClerkNo allow-list field exists — forceRedirectUrl and fallbackRedirectUrlComponent props and NEXT_PUBLIC_CLERK_SIGN_IN_FORCE_REDIRECT_URL / _FALLBACK_REDIRECT_URL environment variablesNot 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:

  1. Scheme. http:// and https:// are different strings. A staging entry copied forward keeps the wrong one.
  2. Trailing slash. https://yourapp.com/auth/callback and https://yourapp.com/auth/callback/ are two different registered URIs on an exact-match provider.
  3. Host form. The apex and the www subdomain are separate hosts and need separate entries, even when one redirects to the other at the edge.
  4. 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.

Tried the fix and still broken?

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.

AI builder × OAuth callback URL not working in prod
BuilderFrequencyPattern
LovableVery highHard-codes redirectTo to Lovable preview URL; production apex never registered.
Bolt.newHighUses bolt.new sandbox redirect URI; custom-domain URL never propagated.
v0HighShips Auth.js without NEXTAUTH_URL; callback URL built from Vercel edge hostname.
CursorMediumWrites dynamic redirectTo but forgets to update Supabase Site URL from localhost.
ReplitMediumLeftover replit.dev preview URL in provider allowlist shadows production host.
Claude CodeLowCorrect runtime code but missing documentation on which providers to update per deploy.
WindsurfLowUpdates Google but not Supabase — flow bounces back to localhost after provider approves.
Base44MediumCustom-domain added in Base44 UI but never synced to Google Cloud or Supabase.

How do I stop OAuth callback URL not working in prod recurring?

Still stuck with OAuth callback URL not working in prod?

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

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
start the triage →

OAuth callback URL not working in prod questions

Why does my OAuth callback work on localhost but fail in production?+
Because OAuth providers enforce an exact-match allowlist of redirect URIs, and your provider (Google, GitHub, or Supabase) only has the localhost URL registered. The provider rejects the callback with redirect_uri_mismatch before your app is ever invoked. You need to add the exact production URL to the provider's allowlist and update any app-side redirectTo value that still hard-codes localhost.
What does the error redirect_uri_mismatch actually mean?+
It means the redirect URI your app sent to Google (or GitHub) does not appear in the list of Authorized redirect URIs registered for that OAuth client. Google compares strings byte-for-byte: https://yourapp.com and https://www.yourapp.com are different, http://yourapp.com and https://yourapp.com are different, and trailing slashes matter. Copy the URL from the error screen exactly and paste it into the provider console — that is the URL you need to allow.
Do I have to update Supabase too, or just the OAuth provider?+
Both. Supabase has its own 'Site URL' and 'Redirect URLs' allowlist that is separate from Google's. If Supabase's Site URL still points to localhost, Supabase rewrites the final redirect back to localhost even after Google approves the sign-in. Set the Site URL to your production domain and add both production and localhost to the Redirect URLs list so local dev keeps working.
How do I handle OAuth callback URLs for multiple environments?+
Register each environment's URL in the provider console. Google supports up to 100 redirect URIs per OAuth client, so add staging, production, and localhost all to the same client. On the app side, derive the redirectTo from window.location.origin rather than hard-coding a string — that way the same code works on every environment without changes. For server-side flows, read from NEXTAUTH_URL or an equivalent env var.
How long does fixing an OAuth callback URL take?+
Ten to fifteen minutes if you have admin access to the OAuth provider console, Supabase, and Vercel environment variables. The actual change is a copy-paste of URLs. Most of the time is spent waiting for a Vercel redeploy after you update NEXTAUTH_URL or the client-side redirect. If something else is wrong — a proxy stripping headers, a middleware rewriting the callback path — budget an extra hour for diagnosis.
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.

OAuth callback URL not working in prod experts

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

Sources