How to fix error "redirect uri mismatch" when login with Google

When asking for help in this category, please make sure to provide the following details:

  • SDK Version(package.json):
    @web3auth/base”: “^9.0.0”,
    @web3auth/ethereum-provider”: “^9.0.0”,
    @web3auth/modal”: “^10.0.5”,
    @web3auth/solana-provider”: “^9.7.0”,

  • Platform: ReactJS in web browser

  • Browser Screenshots:
    image

  • Browser Console Screenshots:

  • Error message:
    Error 400: redirect_uri_mismatch

import { Web3AuthProvider } from '@web3auth/modal/react';
import web3AuthContextConfig from './contexts/web3auth/web3authContext';
import { WagmiProvider } from '@web3auth/modal/react/wagmi';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

<Web3AuthProvider config={web3AuthContextConfig}>
        <QueryClientProvider client={queryClient}>
          <WagmiProvider> {children}</WagmiProvider>
        </QueryClientProvider>
      </Web3AuthProvider>
const web3AuthContextConfig = {
  web3AuthOptions: {
    clientId: clientId,
    web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
    uiConfig: {
      mode: 'dark',
      defaultLanguage: language,
      borderRadiusType: 'medium',
      displayInstalledExternalWallets: true,
      displayExternalWalletsCount: false,
    },
    modalConfig: {
      connectors: {
        [WALLET_CONNECTORS.AUTH]: {
          label: 'auth',
          loginMethods: {
            google: {
              name: 'Google',
              showOnModal: true,
              authConnectionId: 'w3a-google-bth',
            },
            email_passwordless: {
              name: 'Email',
              showOnModal: true,
              authConnectionId: 'w3a-email-btn',
            },
            apple: {
              name: 'Apple',
              showOnModal: false,
            },
            facebook: { showOnModal: false },
            twitter: { showOnModal: false },
            discord: { showOnModal: false },
          },
          showOnModal: true,
        },
        [WALLET_CONNECTORS.METAMASK]: {
          label: 'metamask',
          showOnModal: false,
        },
      },
      hideWalletDiscovery: true,
    },
  },
};
import { useWeb3AuthConnect } from "@web3auth/modal/react";
const { connect } = useWeb3AuthConnect();
<button className="login-button" onClick={() => connect()}>

When connecting to login with google, error “Error 400: redirect_uri_mismatch” occurs
I can’t find the cause, can you help me, thank you!

Thank you for providing detailed information and screenshots. Here’s a summary of your issue for the support team:


Issue Summary

  • SDK & Version:

    • PnP Web SDK (React)
    • @web3auth/base v9.0.0
    • @web3auth/ethereum-provider v9.0.0
    • @web3auth/modal v10.0.5
    • @web3auth/solana-provider v9.7.0
  • Platform:

    • ReactJS (web browser)
  • Problem:

    • Error: Error 400: redirect_uri_mismatch when attempting Google login via Web3Auth Modal.
  • Code Snippets Provided:

    • Web3AuthProvider setup, config object, and login button handler.
  • Screenshots Provided:

    • Browser and console error screenshots (showing the redirect_uri_mismatch error).

Most Likely Cause & Next Steps

The redirect_uri_mismatch error usually means the redirect URI used by the SDK during the Google login flow does not match the one registered in your Web3Auth Dashboard for your project.

Please check the following:

  1. Web3Auth Dashboard Settings

    • Go to Web3Auth Dashboard → Your Project.
    • Under “Whitelisted URLs”, ensure that the URL where your React app is running (including protocol, domain, and port) is added.
      • Example: https://localhost:3000 or your deployed domain.
    • For Google login, Web3Auth handles the OAuth flow, so you do not need to register redirect URIs in your Google Cloud Console (unless using a custom verifier).
  2. Custom Authentication / Verifier

    • If you are using a custom verifier (e.g., your own Google OAuth credentials), make sure the redirect URI in your Google Cloud project matches what Web3Auth expects.
    • If you are using the default Web3Auth Google login, only the Web3Auth Dashboard whitelisted URLs matter.
  3. authConnectionId

    • In your config, you have authConnectionId: 'w3a-google-bth'.
      • Make sure this is correct and matches the connection ID set in your Web3Auth Dashboard, if you have customized it.

Documentation


Next Steps for You

  • Double-check that your app’s URL is correctly whitelisted in the Web3Auth Dashboard.
  • If using a custom Google verifier, ensure the redirect URI in Google Cloud Console matches the one used by Web3Auth.
  • Confirm your authConnectionId is correct.

If you’ve already checked these and the issue persists, please let us know:

  • Are you using a custom verifier or the default Web3Auth Google login?
  • The exact URL your app is running on (as shown in the browser when the error occurs).
  • If possible, the full error message/URL from the browser address bar when the error appears.

This will help the support team assist you further. Thank you!

Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.

Additionally, we would recommend you to join our biweekly Office Hours to get this resolved even faster. Web3Auth Developer Office Hours

Can you please share the message you get when you click on error details ?