Web3Auth Initialization and Oauth Redirect Handling Error

I’m facing issues with Web3Auth initialization and redirect handling in my Next.js application. Here’s a detailed breakdown of the problem:

SDK Version:

  • @web3auth/mpc-core-kit: ^3.1.1
  • @toruslabs/tss-dkls-lib: ^3.0.0

Platform:

  • Next.js application

Errors Encountered:

  • On the second call to init, the tkey property is null.
  • Errors observed when calling handleRedirectResult:
    TypeError: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined
    
    Web3Auth initialization error: CoreKitError: undefined The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined
    
  • Additional error when handling redirect:
    TypeError: can't access property "typeOfUser", torusKey.metadata is undefined
    getPostboxKey torus.js:67
    _getPostBoxKey mpcCoreKit.js:1121
    handleRedirectResult mpcCoreKit.js:380
    init mpcCoreKit.js:233
    getWeb3AuthInstance web3Auth.ts:26
    

Code Snippet:

export const getWeb3AuthInstance = async (): Promise<Web3AuthMPCCoreKit> => {
  if (!web3AuthInstance) {
    web3AuthInstance = new Web3AuthMPCCoreKit({
      web3AuthClientId,
      web3AuthNetwork: WEB3AUTH_NETWORK.DEVNET,
      tssLib: tssLib,
      storage: window.localStorage,
      baseUrl: 'http://localhost:3000',
      uxMode: UX_MODE.REDIRECT,
      manualSync: true,
      redirectPathName: 'auth',
    });

    if (web3AuthInstance.status === COREKIT_STATUS.NOT_INITIALIZED) {
      await web3AuthInstance.init({ handleRedirectResult: true });
    }
  }
  return web3AuthInstance;
};

Troubleshooting Done:

  • Verified that web3AuthInstance is not null before calling methods.
  • Ensured web3AuthInstance.init() is awaited and status is checked.
  • Tried setting handleRedirectResult to false, but the issue persists.

Additional Code Snippet:

const signInWithGoogle = async () => {
  try {
    setLoading(true);
    const web3AuthInstance = await getWeb3AuthInstance();
    await web3AuthInstance.loginWithOAuth(googleVerifierConfig);
  } catch (error) {
    console.error("Error logging in", error);
  } finally {
    setLoading(false);
  }
};

Can anyone help diagnose why tkey is null after initialization on redirect from OAuth and why handleRedirectResult throws these errors? Am I missing something?

Thank you.

Thank you for the detailed breakdown of the issue you’re encountering, CJ. I’ve gathered all the relevant information regarding your error to assist the support team in resolving your issue swiftly.

Summary

SDK Details:

  • SDK: tKey JS SDK
  • SDK Version:
    • @web3auth/mpc-core-kit: ^3.1.1
    • @toruslabs/tss-dkls-lib: ^3.0.0

Platform:

  • Platform: Next.js application

Errors Encountered:

  1. On the second call to init, the tkey property is null.
  2. Errors when calling handleRedirectResult:
    TypeError: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined
    
  3. Web3Auth initialization error:
    CoreKitError: undefined The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined
    
  4. Additional error when handling redirect:
    TypeError: can't access property "typeOfUser", torusKey.metadata is undefined
    getPostboxKey torus.js:67
    _getPostBoxKey mpcCoreKit.js:1121
    handleRedirectResult mpcCoreKit.js:380
    init mpcCoreKit.js:233
    getWeb3AuthInstance web3Auth.ts:26
    

Code Snippets:

  1. Web3Auth Initialization:

    export const getWeb3AuthInstance = async (): Promise<Web3AuthMPCCoreKit> => {
      if (!web3AuthInstance) {
        web3AuthInstance = new Web3AuthMPCCoreKit({
          web3AuthClientId,
          web3AuthNetwork: WEB3AUTH_NETWORK.DEVNET,
          tssLib: tssLib,
          storage: window.localStorage,
          baseUrl: 'http://localhost:3000',
          uxMode: UX_MODE.REDIRECT,
          manualSync: true,
          redirectPathName: 'auth',
        });
    
        if (web3AuthInstance.status === COREKIT_STATUS.NOT_INITIALIZED) {
          await web3AuthInstance.init({ handleRedirectResult: true });
        }
      }
      return web3AuthInstance;
    };
    
  2. OAuth Login:

    const signInWithGoogle = async () => {
      try {
        setLoading(true);
        const web3AuthInstance = await getWeb3AuthInstance();
        await web3AuthInstance.loginWithOAuth(googleVerifierConfig);
      } catch (error) {
        console.error("Error logging in", error);
      } finally {
        setLoading(false);
      }
    };
    

Browser Console Screenshots:

  • [Screenshots should be checked if provided]

Troubleshooting Done:

  • Verified that web3AuthInstance is not null before calling methods.
  • Ensured web3AuthInstance.init() is awaited and status is checked.
  • Tried setting handleRedirectResult to false, but the issue persists.

Next Steps:

  1. Verify the configurations in the init and loginWithOAuth method to ensure all required parameters are properly set.
  2. Double-check the Google OAuth verifier configuration.
  3. Share the browser console screenshots if not already included.

This response was generated by the Web3Auth Bot, and a person from the Web3Auth team will come and give a more detailed answer to your query shortly.

I had not deployed a verifier.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.