DEV Community

AI App Medic
AI App Medic

Posted on Originally published at aiappmedic.com

Fix Google redirect_uri_mismatch with Supabase Auth

The user clicks Sign in with Google, a Google page appears, and it stops with Error 400: redirect_uri_mismatch. They never reach your Lovable, Bolt, or Cursor app. Google is rejecting the callback URL before Supabase issues a session. This is not a broken button, and it is not the same as a login that works and then drops the user on localhost:3000.

What Google is actually checking

Your app calls supabase.auth.signInWithOAuth({ provider: "google" }). Supabase sends the browser to Google with your project's Client ID and a redirect_uri. That URI is Supabase's own callback, normally:

https://YOUR_PROJECT_REF.supabase.co/auth/v1/callback
Enter fullscreen mode Exit fullscreen mode

Google continues only if that exact string is listed under Authorized redirect URIs on the same OAuth client. Scheme, host, path, and trailing slash all have to match. Your app address, such as https://your-app.lovable.app/auth/callback or https://www.example.com, is not what Google checks, so adding only that address does not fix the error.

After Google accepts the callback, Supabase signs the user in and sends them to your redirectTo URL, or to the project's Site URL. That second hop is configured in Supabase, not in Google.

Copy the URI from the error, not from memory

  1. Reproduce the error and open Error details (sometimes labelled Request details). You should see a line like redirect_uri=https://abcd1234.supabase.co/auth/v1/callback.
  2. You can also read it from the address bar. The Google URL contains redirect_uri= in encoded form: https:// shows up as https%3A%2F%2F. Decode it once.
  3. Paste that string into Google character for character. Do not add a trailing slash or swap the project ref for your app domain.

Edit the client whose ID is in Supabase

In Supabase, open Authentication, Providers, Google, and copy the Client ID (it looks like .apps.googleusercontent.com). In Google Cloud, open Google Auth Platform, then Clients, and open the client whose ID is identical. Check the project picker at the top; it is easy to be in the wrong Google Cloud project.

The client type must be Web application. An iOS, Android, or Chrome extension client will not accept this callback, and a second web client will not help if Supabase still has the first client's ID and secret.

Add the callback under Authorized redirect URIs

On that client, under Authorized redirect URIs, add the callback from the Supabase Google provider page. It should match what you copied above:

https://YOUR_PROJECT_REF.supabase.co/auth/v1/callback
Enter fullscreen mode Exit fullscreen mode

No trailing slash. Use https. For the Supabase CLI locally, the docs use http://127.0.0.1:54321/auth/v1/callback. Google allows plain http only for localhost addresses.

If a Supabase custom domain is active, Auth advertises that host as the callback. Add both:

https://YOUR_PROJECT_REF.supabase.co/auth/v1/callback
https://auth.example.com/auth/v1/callback
Enter fullscreen mode Exit fullscreen mode

Use your real custom domain in the second line (commonly auth.example.com or api.example.com). Save the client. Google can take from a few minutes up to a few hours to apply the change, so an immediate failed test is not proof the URI is still wrong.

Put your app URL in the two places it does belong

Your app origin goes in these two places, not in Google's redirect URI list:

  • Google, Authorized JavaScript origins: https://your-app.com, plus https://www.your-app.com if you serve both, plus your .lovable.app or .bolt.host preview origin while you still use it. Origin only: no path, no trailing slash. A mistake here produces a different error, origin_mismatch.
  • Supabase, Authentication, URL Configuration, Redirect URLs: the page users return to, for example https://your-app.com/auth/callback, plus the same path on www and on the preview host. Set Site URL to your production origin, not http://localhost:3000.

In the app, pass that return URL explicitly:

await supabase.auth.signInWithOAuth({
  provider: "google",
  options: {
    redirectTo: window.location.origin + "/auth/callback",
  },
});
Enter fullscreen mode Exit fullscreen mode

If you just added a custom domain, confirm the new origin is in the Redirect URLs list, and that Google has the new Supabase callback.

If Google succeeds but the app still shows you as logged out

The mismatch error is gone, so the Google client is fine. Usual leftovers: the return URL is missing from Supabase Redirect URLs (Auth falls back to Site URL, often still localhost), redirectTo still has an old preview origin, or a server-rendered callback (v0, Next.js) never calls exchangeCodeForSession. If the consent screen is in Testing and the account is not a test user, you get an access blocked message, not redirect_uri_mismatch. If the user returns with error_description=Database+error+saving+new+user in the URL, a trigger on auth.users failed. If Supabase could not exchange the external code, re-copy the client secret from the same Web application client.

When you create a new Google client, paste the callback from the Supabase provider page first. When you add a production or Supabase custom domain, update Google and Supabase together.

The full guide is at https://aiappmedic.com/guides/supabase-google-oauth-redirect-uri-mismatch . You can also run a free scan of your app at https://aiappmedic.com/scan .

Top comments (0)