When developing apps that involve OAuth 2.0 authentication or third-party login integrations like Google, GitHub, or Facebook, it is common to encounter the redirect_uri_mismatch error. This issue often arises in modern development stacks like React on the front end and Node.js or Express on the back end. Although frustrating, solving this error involves a structured approach to diagnosing and correcting misconfigurations in redirect URIs.
Understanding the Redirect URI Mismatch Error
At its core, the redirect_uri_mismatch error occurs when the URI provided in the authentication request doesn’t exactly match the allowed redirect URIs registered in the OAuth provider’s settings. OAuth 2.0 is very strict in validating the redirect URI – even small differences like a missing trailing slash or a different protocol (e.g., https vs http) can trigger a mismatch.
Here’s what typically happens:
- The client (e.g., a React app) initiates the OAuth flow.
- The authentication provider redirects the user back to the client using the
redirect_uri
specified in the request. - If that URI doesn’t match one of the predefined allowed URIs in the provider’s configuration, it throws a
redirect_uri_mismatch
error.

Why This Error Happens in React and Node.js Projects
React applications, when served via development servers like Webpack DevServer or Vite, often use localhost with specific ports (e.g., http://localhost:3000). On the other hand, Node.js back ends (e.g., using Express) may reside on a different port (e.g., http://localhost:5000). During the authentication process, if the redirect URI submitted from the front end doesn’t match what the OAuth provider expects, the error is triggered.
Here are some common reasons for mismatch:
- Incorrect protocol (HTTPS vs HTTP)
- Trailing slash issues (e.g.,
/callback
vs/callback/
) - Port number differences on localhost
- Wrong environment URI in production or staging
Resolving Redirect URI Mismatch in Common Scenarios
1. In React Applications
React apps often initiate OAuth flows from the browser. This means that the redirect URI is client-side and must be properly registered with the OAuth provider.
Steps to solve:
- Go to your OAuth provider’s developer console (e.g., Google Developer Console).
- Under the credentials or OAuth client entries, find the registered redirect URIs.
- Add exactly the URI you are using in the app. For example:
http://localhost:3000/oauth2/callback
- Ensure you are not including query parameters in the redirect URI registration (these are ignored during validation).
If you’re using libraries like react-google-login
or libraries from Auth0, make sure the redirect URI used in your config matches exactly what is registered in the provider’s system.
2. In Node.js / Express Back Ends
When the OAuth flow is handled server-side, the redirect URI should point to an endpoint on your server that receives the OAuth code and completes the token exchange.
Steps to solve:
- Determine your redirect URI endpoint, such as:
http://localhost:5000/auth/google/callback
- Ensure that your server is listening on this exact route and that your request includes the correct
redirect_uri
parameter. - Update it in the client config passed to the OAuth provider or SDK.
- Log the redirect URI dynamically and verify it matches exactly with your provider’s registered URI.
Use environment variables to define redirect URIs, especially when deploying to multiple environments like staging and production.
3. With Third-Party Authentication Libraries
Using libraries like Passport.js, Firebase Authentication, or Auth0 can simplify OAuth login processes. However, they follow the same rules and are equally sensitive to URI mismatches.
Tips:
- Carefully follow the library’s documentation about configuring redirect URIs.
- When using social logins through middlemen like Firebase or Auth0, update URIs in the identity provider (e.g., Facebook or Google developer accounts).
- For SaaS platforms, also make sure the base domain is registered (e.g.,
https://yourapp.com/callback
instead of localhost links).

Debugging Tools and Techniques
Debugging this type of error involves careful observation and comparing URIs character-for-character. Useful tools include:
- Browser Dev Tools: Look at network requests and the actual redirect URI being used.
- Logging: Use
console.log
(React) orreq.query
/req.body
in Node.js to print values in the auth flow. - OAuth Provider Logs: Platforms like Google might show recent errors and URIs for failed login attempts.
Best Practices to Avoid Future Issues
- Use Environment Variables: Store redirect URIs in
.env
files for both client and server. This ensures consistency between environments. - Trailing Slash Consistency: Decide whether or not to use trailing slashes and be consistent. Both in the frontend code and provider settings.
- HTTPS in Production: Always use
https://
redirects in production for security and to match the OAuth provider’s expectations. - Centralized Config Management: Store allowed redirect URIs in a shared config file or documentation to avoid confusion across team members.
- Test Every Environment: Remember, dev, staging, and prod may all have unique base URLs and require separate entries.
Frequently Asked Questions (FAQ)
- Q1: What is a redirect URI in OAuth?
- A redirect URI is the endpoint to which an OAuth provider redirects the user after they authorize your app. The URI is used to resume the authentication process and obtain tokens.
- Q2: Why does redirect_uri_mismatch happen even if I typed my URI correctly?
- The error can occur due to subtle differences like trailing slashes, ports, or typo errors. OAuth providers compare URIs character-by-character.
- Q3: Can I use localhost redirect URIs in production?
- No. For production, you must register redirect URIs using your live domain with HTTPS. Localhost should only be used for development.
- Q4: Can I add multiple redirect URIs for one application?
- Yes, most OAuth providers allow registering multiple valid redirect URIs. You should register one for each environment your app runs in.
- Q5: Is there a way to bypass redirect URI validation?
- No. OAuth standards require strict validation for security reasons. The only solution is to ensure your URIs are perfectly matched.
By understanding what causes the redirect_uri_mismatch error and how to properly configure the URI in both the app and the provider console, developers can ensure smooth authentication flows. Whether working in React, Node.js, or another stack, the key is precision and alignment of your redirect settings across all components.