DEV Community

AppFirstAid
AppFirstAid

Posted on Originally published at appfirstaid.com

Google sign-in "Error 400: redirect_uri_mismatch" after a domain move: find the exact address and fix it

Originally published on AppFirstAid.

Short answer: Google only sends people back to addresses you listed in advance, and the one your app just asked for isn't on the list. Find the exact redirect_uri your sign-in request uses, then add it, character for character, under Authorized redirect URIs on your OAuth client in the Google Cloud console. Google's docs say the scheme (http or https), the letter case and the trailing slash all have to match, and wildcards aren't allowed.

Signs this is your problem

  • Clicking "Continue with Google" shows Error 400: redirect_uri_mismatch instead of the account picker.
  • It started after you moved to a custom domain, renamed a project, turned on a custom domain for your backend, or deployed to a new host.
  • It works on one address (a preview link or localhost) but not another.

Why it happens

When your app starts Google sign-in, it passes a redirect_uri telling Google where to send the person back. Google compares it with the list saved on your OAuth client and it must match exactly. https://yourdomain.com/callback and https://yourdomain.com/callback/ are two different addresses, and so are www and non-www.

Step 1: find the address your app actually sends

  1. Open your app in a private window and click the Google button.
  2. On Google's page, find redirect_uri= in the address bar and decode it (%3A is :, %2F is /).
  3. Write it down exactly. That's the one Google needs.

What you'll usually see:

  • Supabase Auth: https://<project-ref>.supabase.co/auth/v1/callback. Moving your app to a new domain doesn't change it, but turning on a custom domain for the Supabase project itself does, so add the new callback (e.g. https://api.yourdomain.com/auth/v1/callback) alongside the old one.
  • Firebase Authentication: https://<project>.firebaseapp.com/__/auth/handler by default; if you set authDomain to your own domain, add https://<your-domain>/__/auth/handler.
  • Auth.js (NextAuth): https://yourdomain.com/api/auth/callback/google.
  • Your own code: whatever your server passes; check it's built from the live domain, not a preview or localhost.

Step 2: add it to your Google OAuth client

  1. In the Google Cloud console, open the Clients page of the Google Auth Platform (older screens: Credentials) and open the Web application client whose Client ID your app uses. Projects often have several, so match the ID.
  2. Under Authorized redirect URIs, add the exact address from step 1. Keep the old one if anyone still signs in there.
  3. Under Authorized JavaScript origins, add your live site as scheme and domain only, like https://yourdomain.com.
  4. Save, wait (Google's help says 5 minutes to a few hours), and retest in a fresh private window on the live domain.

The related one: "The JavaScript origin in the request does not match"

That message is about the page that started sign-in, not the return address. Copy the origin shown in the error and add it under Authorized JavaScript origins on the same client, with no path, query or trailing slash. If people use both yourdomain.com and www.yourdomain.com, add both.

Still landing on the old preview link after Google?

If Google sign-in finishes but people end up on localhost or an old preview URL, that's your auth service's redirect settings, not Google. See Login broke after I added my custom domain.


The full guide, with the exact error text Google shows for each case, is here: Fix Google redirect_uri_mismatch. If you'd rather not check every setting by hand, AppFirstAid runs a free scan of your live app's sign-in and setup.

Top comments (0)