How to convert code from @web3auth/no-modal to @web3auth/modal?

  • SDK Version(package.json):
    @web3auth/base”: “^9.7.0”,
    @web3auth/modal”: “^10.0.5”,
    @web3auth/no-modal”: “^9.0.0”,
  • Platform: ReactJS in web browser

The ReactJS project was previously using the @web3auth/no-modal library to implement login to the Solana network using Google and Email passwordless.
Now, I need to add the Apple login feature, which requires switching to @web3auth/modal.
However, I couldn’t find any official documentation or examples for migrating from @web3auth/no-modal to @web3auth/modal.
I’ve tried implementing it manually, but encountered the errors listed below.
Hope to get help with a tutorial or example. Thank you.

const web3AuthConfig = walletType => ({
    privateKeyProvider: getPrivateKeyProvider(walletType),
    enableLogging: true,
    clientId: clientId,
    uiConfig: {
      defaultLanguage: currentLang,
      logoLight: logoLight,
      logoDark: logoDark,
    },
  });

  const createAuthAdapterConfig = walletType => ({
    adapterSettings: {
      uxMode: UX_MODE.REDIRECT,
      loginConfig: {
        google: {
          verifier,
          verifierSubIdentifier: googleVerifier,
          typeOfLogin: 'google',
          clientId: googleClientId,
        },
        email_passwordless: {
          verifier,
          verifierSubIdentifier: emailVerifier,
          typeOfLogin: 'email_passwordless',
          clientId,
        },
      },
    },
    privateKeyProvider: getPrivateKeyProvider(walletType),
  });


      
const web3AuthInstance = new Web3AuthNoModal(web3AuthConfig(walletType));
const authAdapter = new AuthAdapter(createAuthAdapterConfig(walletType));


 web3AuthInstance.configureAdapter(authAdapter);


 await web3AuthInstance.init();

await web3Login.connectTo(WALLET_ADAPTERS.AUTH, {
        loginProvider: 'google',
      });
  • New code has been moved to @web3auth/modal:
import { WEB3AUTH_NETWORK } from '@web3auth/modal';
import { chainConfigSolana, keyEnvConfig } from './config';

const { clientId } = keyEnvConfig;

const web3AuthContextConfig = {
  web3AuthOptions: {
    clientId: clientId,
    web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
    chains: [chainConfigSolana],
    hideWalletDiscovery: true,
  },
};
export default web3AuthContextConfig;

Web3AuthProvider config={web3AuthContextConfig}>
        <QueryClientProvider client={queryClient}>
          <WagmiProvider> {children}</WagmiProvider>
        </QueryClientProvider>
      </Web3AuthProvider>

await connectTo(WALLET_CONNECTORS.AUTH, {
        authConnection: AUTH_CONNECTION.GOOGLE,
        authConnectionId: 'w3a-google-bth',
      });

  • Browser Console Screenshots:
  • Error occurred when calling connectTo function from useWeb3AuthConnect()

Thank you for your detailed question and for providing your code and error screenshots! Here’s a summary and guidance to help you migrate from @web3auth/no-modal to @web3auth/modal in your ReactJS project, specifically for Solana with Google, Email Passwordless, and now Apple login.


Summary of Your Setup & Issue

  • SDKs Involved: Migrating from @web3auth/no-modal (v9.0.0) to @web3auth/modal (v10.0.5)
  • Platform: ReactJS (Web)
  • Chain: Solana
  • Login Methods: Google, Email Passwordless (existing); Apple (to be added)
  • Problem: Difficulty migrating code to the new unified SDK and encountering errors with the new connectTo usage.

Key Migration Points

1. Remove Deprecated Packages

Ensure you have removed:

  • @web3auth/no-modal
  • @web3auth/base
  • @web3auth/auth-adapter
  • Any other v9-specific packages

2. Install Only the Latest SDKs

For React:

npm install @web3auth/modal @web3auth/modal/react

(You do not need @web3auth/no-modal or @web3auth/base anymore.)

3. Centralize Configuration in the Dashboard

  • All login providers (Google, Email, Apple) and chain configs should be set up in the Web3Auth Developer Dashboard.
  • Each login method will have a unique Connection ID (e.g., w3a-google-bth).

4. Update Your Code to Use v10 Patterns

  • No more adapters, no more manual chainConfig.
  • Use the Web3AuthProvider and hooks from @web3auth/modal/react.

Example Setup:

import { Web3AuthProvider, useWeb3AuthConnect, WALLET_CONNECTORS, AUTH_CONNECTION } from '@web3auth/modal/react';

const web3AuthContextConfig = {
  web3AuthOptions: {
    clientId: "<YOUR_CLIENT_ID>",
    web3AuthNetwork: "sapphire_mainnet",
    // No need for chains array unless you have custom chains
    modalConfig: {
      connectors: {
        [WALLET_CONNECTORS.AUTH]: {
          loginMethods: {
            google: {
              name: "Google",
              showOnModal: true,
              authConnectionId: "w3a-google-bth", // from dashboard
            },
            email_passwordless: {
              name: "Email",
              showOnModal: true,
              authConnectionId: "w3a-email-bth", // from dashboard
            },
            apple: {
              name: "Apple",
              showOnModal: true,
              authConnectionId: "w3a-apple-bth", // from dashboard
            },
          },
        },
      },
    },
  },
};

export default web3AuthContextConfig;

Provider in App:

<Web3AuthProvider config={web3AuthContextConfig}>
  {/* ... */}
</Web3AuthProvider>

Connecting with a Provider:

const { connect } = useWeb3AuthConnect();

await connect(WALLET_CONNECTORS.AUTH, {
  authConnection: AUTH_CONNECTION.GOOGLE, // or EMAIL_PASSWORDLESS, APPLE
  authConnectionId: "w3a-google-bth", // match with dashboard
});
  • Note: connectTo is for non-React usage. In React, use the connect hook.

5. Error Handling

  • The error in your screenshot suggests a mismatch in the connection details or a missing configuration in the dashboard.
  • Double check that the authConnectionId matches exactly what’s in your dashboard.
  • Make sure the Apple login is enabled and configured in your dashboard.

References & Migration Guides


Action Items for You

  1. Update your dependencies as above.
  2. Remove all v9 code patterns (adapters, manual chainConfig, etc.).
  3. Configure all login methods in the Dashboard and use their authConnectionId in your code.
  4. Use the React hooks (useWeb3AuthConnect) for login actions.
  5. If you still see errors, please provide:
    • The exact error message (not just screenshot)
    • Your current web3AuthContextConfig and how you call connect
    • Confirmation that your dashboard setup matches the authConnectionId used

Let us know if you need a more specific code sample for your use case, or if you run into any more migration errors!

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

Thank you very much for your reply!

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!