Google OAuth redirect_uri_mismatch in Production: Fix
Google sign-in works on localhost but shows Error 400: redirect_uri_mismatch on your live site? Find the exact URI your app sends and make it match the Google Cloud console, character by character.
"Error 400: redirect_uri_mismatch" means the redirect URI your app sent to Google is not an exact match for any entry in "Authorized redirect URIs" on that OAuth client. The fix is to read the exact URI from Google's error page, compare it with the console entry, and make them identical, including scheme, host, port, path and trailing slash.
It usually shows up the day you deploy. Localhost was registered while you built the app. The production domain was not, or your server is sending a different URI than you think. This guide finds the real cause in order, with a Node.js and Express example that applies to any backend.
Step 1: Get the Exact URI Google Received
Do not guess. Google's error page has a link called "error details". It shows the redirect_uri it received. Community threads on this error give the same first step: compare what the request sent with what the console holds.
You can also read it from the browser. Open the network tab, start the sign-in, and look at the request to accounts.google.com. Copy the redirect_uri query parameter and URL-decode it. Now you have the value that has to be registered.
Step 2: Register It Under the Right Field
In Google Cloud console, open your project, then APIs and Services, then Credentials, then your OAuth 2.0 Client ID. There are two similar fields:
- Authorized JavaScript origins: a bare origin such as
https://app.example.com. No path. - Authorized redirect URIs: the full callback URL such as
https://app.example.com/auth/google/callback.
Adding the URI to the JavaScript origins field does not fix this error. It has to be in the redirect URIs field. Save, then retry. Changes can take a few minutes to apply, so wait before assuming the entry is wrong.
Step 3: Match Every Character
The comparison is exact. Check each part:
- Scheme.
http://andhttps://are different. Production should behttps://. - Host.
example.comandwww.example.comare different. - Port.
localhost:3000/callbackandlocalhost:5173/callbackare different URIs. - Path and case.
/auth/google/callbackis not/auth/Google/callback. - Trailing slash.
/callbackand/callback/are different.
A short debugging guide on dev.to lists the same kinds of small differences. Register one entry per environment: local, staging and production each get their own line.
Step 4: Check That Production Uses the Production Callback URL
Many apps read the callback from an environment variable. If production still has the localhost value, the app sends the wrong URI no matter what the console says.
// config.js
const callbackURL = process.env.GOOGLE_CALLBACK_URL;
if (!callbackURL) {
throw new Error("GOOGLE_CALLBACK_URL is not set");
}
console.log("OAuth callback in use:", callbackURL);
export { callbackURL };
Log it once at startup and read the production log. If it prints a localhost URL, fix the variable in your host's settings and redeploy. Also check that production uses the same client ID and secret you edited. A Vercel community thread covers this kind of setup mix-up after a new production client was created.
Step 5: Fix http vs https Behind a Proxy
This is the most common cause when the console entry looks perfect. If your app builds the callback from the incoming request, and TLS ends at a proxy or platform router, the app sees plain HTTP and sends http://app.example.com/....
In Express, tell the app to trust the proxy so req.protocol reflects the original scheme:
import express from "express";
const app = express();
// 1 = trust the first proxy in front of the app
app.set("trust proxy", 1);
The proxy must also forward the original scheme. For nginx:
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
If you use Passport, set the callback as an absolute URL in the strategy options instead of a relative path. Many libraries also have a proxy: true option for this case. A fixed, absolute callback from an environment variable is the safest choice because the proxy cannot change it.
Step 6: Rule Out Rules Google Enforces on URIs
Some URIs are rejected when you try to save them, so you may think the entry exists when it does not. Check that:
- The production URI uses
https. Plainhttpis accepted only for localhost. - It is a real domain, not a bare IP address.
- It has no wildcard. Each callback must be listed in full.
If the console shows a red error under the field, the entry was not saved. Fix it and save again.
Step 7: Watch the Other Google Sign-In Errors
Once the mismatch is fixed, a different error can appear. "Access blocked: this app's request is invalid" and "app not verified" come from the consent screen setup, not the redirect. One Vercel thread shows the second one. If the consent screen is still in testing mode, only listed test users can sign in. Publish the app, or add the users, before you announce a launch.
Then test the real flow. Sign in with a fresh account in a private window on the production domain, not just on your laptop.
How Relia Helps
Sign-in failures are costly because the user leaves and you never hear about it. Relia watches the users and APIs of a live product, joins related signals, such as a deploy and a rise in failed requests on your callback route, into one incident explained in plain words, and shows who was affected. After a deploy, it checks whether the problem went away. You can add uptime checks for key pages such as your login page. Install with npx relia-sdk@latest init for Node.js and browser apps. There is a Free plan, and a live demo at app.tryrelia.com/demo. For a related login problem, see Lovable Supabase login fails after publish.
FAQ
Why does Google sign-in work on localhost but not in production?
Localhost is registered as a redirect URI, but the production URL is not, or production sends a different URI than the one registered. Compare the redirect_uri in the error details with the console entry.
What is the difference between authorized JavaScript origins and redirect URIs?
Origins are bare domains for browser-side requests. Redirect URIs are full callback URLs that Google sends the user back to. This error needs the redirect URI field.
Can I use a wildcard in the redirect URI?
No. List each callback URL in full, one per environment.
How long do changes in the Google console take?
Usually a few minutes. If the entry is correct after that, the app is sending a different URI than the one you registered.
Why is my app sending http instead of https?
TLS ends at a proxy, so the app sees plain HTTP. Trust the proxy and forward X-Forwarded-Proto, or set the callback as a fixed absolute https URL in an environment variable.
For session and token problems after login works, read JWT expired errors in production.