Error logging or throwing exceptions from modal on flutter mobile apps

Is there any way for the modal to return errors that we can handle? Or to know if there are geographical restrictions for users for example? We are using cyan but most of our users are in the middle east (i.e. Lebanon).

Sometimes the modal works, sometimes it doesn’t, but we have no access to error logs when it doesn’t work. Is there a way for the modal to throw an exception that we can get visibility on, rather than just presenting an error message to the user?

Please provide the Web3Auth initialization and login code snippet below:

Init code

  final loginConfig = HashMap<String, LoginConfigItem>();
  loginConfig['jwt'] = LoginConfigItem(
    verifier: Env.web3authVerifier, // get it from web3auth dashboard
    typeOfLogin: TypeOfLogin.jwt,
    name: "firebase",
    clientId: Env.web3authCliendId, // web3auth's plug and play client id
  );

  Network web3authNetwork;

  if (Env.firebaseProjectId == "our-id") {
    web3authNetwork = Network.cyan;
  } else {
    web3authNetwork = Network.testnet;
  }

  await Web3AuthFlutter.init(
    Web3AuthOptions(
      clientId: Env.web3authCliendId,
      network: web3authNetwork,
      redirectUrl: redirectUrl,
      loginConfig: loginConfig,
    ),
  );

Login code

  Future launchWeb3Auth() async {
    final firestoreUser = context.read<FirestoreUser?>();
    try {
      final prefs = await SharedPreferences.getInstance();

      var idToken = (await FirebaseAuth.instance.currentUser!.getIdToken(true))
          .toString();

      if (Env.useEmulator) {
        idToken = await signJwtLocallyForWeb3Auth(idToken);
      }

      final Web3AuthResponse result = await Web3AuthFlutter.login(
        LoginParams(
          mfaLevel: web3enums.MFALevel.NONE,
          loginProvider: web3enums.Provider.jwt,
          extraLoginOptions: ExtraLoginOptions(
            id_token: idToken,
            domain: "firebase",
          ),
        ),
      );

    } on UserCancelledException {
      logger.e("User cancelled.");
      await signOut();
    } on PlatformException catch (e) {
      logger.e("Platform exception.");
      if (e.code == "LoginFailedException") {
        await signOut();
      }
    } catch (e) {
      logger.e(e);
      await signOut();
    }
  }

Log out code

Future<void> signOut() async {
  try {
    // Clear private key
    SharedPreferences preferences = await SharedPreferences.getInstance();
    final pk = preferences.get("privateKey");
    if (pk != null && pk != "") {
      // await Web3AuthFlutter.logout(); // THIS LOGOUT IS NOT WORKING
      await preferences.clear();
    }

    await FirebaseAuth.instance.signOut();
  } catch (e) {
    logger.e(e);
    showSnackBar("An unexpected error has occurred");
  }
}```

@maseh One can get callback from modal either by closing it or after success/failure callback redirection but not in the middle of login. We are working hard for improving error tracing and better handling of errors.

1 Like

I noticed the error handling works better on the new release of the flutter sdk (2.0.0). Would be awesome if we could see these important updates on the pub dev changelog as well.

Thank you for hard work on this :pray:

It will be released soon on pub dev. Thanks for you patience and continued support.

@maseh This has been released and fixed.