thirdweb-dev / js

Best in class web3 SDKs for Browser, Node and Mobile apps
https://thirdweb.com
Apache License 2.0
409 stars 292 forks source link

[React Native] [Thirdweb v5] ERROR TypeError: Cannot read property 'readFile' of undefined, js engine: hermes #3645

Open ludwig-g-w opened 1 month ago

ludwig-g-w commented 1 month ago

It seems like this error has reappeared for me without any relevant changes to my dependencies. I've tried to create a new Thirdweb client Id which hasn't solved the issue. Here's the error:

ERROR TypeError: Cannot read property 'readFile' of undefined, js engine: hermes Error: Malformed response from post authentication: Something went wrong getting cognito recovery code

joaquim-verges commented 1 month ago

@ludwig-g-w what are the steps you're doing to reproduce this? some code would be helpful too. And is it consistently failing with that error?

ludwig-g-w commented 1 month ago

I encounter this error consistently whenever I try to login using whatever method otp, Apple(I think same result when using wallets as well) native wallet works fine. The strange thing is that two weeks ago these same methods were working, no changes in the code since then. The only change I have done now is to update my API key.

ludwig-g-w commented 1 month ago

I don't know if it's of any help but the error is pointing to this file: getSSOTokenFromFile.js

"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSSOTokenFromFile = void 0; const fs_1 = require("fs"); const getSSOTokenFilepath_1 = require("./getSSOTokenFilepath"); const { readFile } = fs_1.promises; const getSSOTokenFromFile = async (id) => { const ssoTokenFilepath = (0, getSSOTokenFilepath_1.getSSOTokenFilepath)(id); const ssoTokenText = await readFile(ssoTokenFilepath, "utf8"); return JSON.parse(ssoTokenText); }; exports.getSSOTokenFromFile = getSSOTokenFromFile;

joaquim-verges commented 1 month ago

hmmm that code doesnt look familiar, its not from our library - is it from another library maybe?

ludwig-g-w commented 1 month ago

After looking a bit further it seems to be this function that is throwing the error: Something went wrong getting cognito recovery code

async function getRecoveryCode(
  storedToken: AuthStoredTokenWithCookieReturnType["storedToken"],
  client: ThirdwebClient,
  recoveryCode?: string,
): Promise<string> {
  if (
    storedToken.authDetails.recoveryShareManagement ===
    RecoveryShareManagement.CLOUD_MANAGED
  ) {
    if (
      storedToken.authProvider === AuthProvider.CUSTOM_JWT ||
      storedToken.authProvider === AuthProvider.CUSTOM_AUTH_ENDPOINT
    ) {
      if (!recoveryCode) {
        throw new Error(
          `GetRecoveryCode error: ${ErrorMessages.missingRecoveryCode}`,
        );
      }
      return recoveryCode;
    } else {
      try {
        const code = await getCognitoRecoveryPassword(client);
        return code;
      } catch (e) {
        throw new Error("Something went wrong getting cognito recovery code");
      }
    }
  } else if (
    storedToken.authDetails.recoveryShareManagement ===
    RecoveryShareManagement.USER_MANAGED
  ) {
    if (recoveryCode) {
      return recoveryCode;
    }
    throw new Error(ErrorMessages.missingRecoveryCode);
  } else {
    throw new Error("Invalid recovery share management option");
  }
}
joaquim-verges commented 1 month ago

how consistent is this? you can reproduce everytime?

ludwig-g-w commented 1 month ago

It always happens for me in two different apps as well.

joaquim-verges commented 1 month ago

very weird im not able to reproduce. Does it happen with every email for you or only certain ones? the error seems to indicate that either the account or client id was used in a different way before...

joaquim-verges commented 3 weeks ago

@ludwig-g-w can you try updating to latest (5.43+) we shipped a fix related to this issue