Web3Auth Plugin issue

  • SDK Version: 5.0.3
  • Platform: android and ios

when we are using flutter plugin of web3auth when user put an otp in the authentication after that it generates the private key but then it doesn’t authenticate with response sometime it redirects to login even after keys are generated? how can we solve this

but after sometime it passes the checks and is authenticated but sometime after 2 and 3 attempts it doesn’t work as it should.

Thank you for reaching out, Muhammad Waqar! I can help summarize your issue so our support team can assist you effectively.

Issue Summary:

  • SDK Details: PnP Flutter SDK
  • SDK Version: 5.0.3
  • Platforms: Android and iOS
  • Issue Description: After entering an OTP for authentication, the SDK generates a private key but does not consistently authenticate the user. Sometimes, it redirects back to login even after the keys are generated. This issue occurs intermittently—after 2 to 3 attempts, it may work properly.

Next Steps:

For our support team to further investigate, it would be helpful if you could provide:

  • Web3Auth Initialization & Login Code Snippets: Showing how you’re integrating the SDK.
  • Browser Console Screenshots: If applicable, to capture any errors or logs.
  • Verifier Name and Method of Login: If you’re using custom authentication.

If you have any additional links or images related to your issue, please do share!

We appreciate your patience, and I hope we can get this resolved for you quickly!

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.

Hey @muwaqar.qsol,

Could you please share the Web3Auth initialization and login code? That will help me assist you better.
Thank you!

VoidCallback loginF(
    GlobalKey<FormState> loginformKey,
    BuildContext context,
    Future<Web3AuthResponse> Function() method,
  ) {
    return () async {
      try {
        // await context.read<ConnectivityCubit>().checkInternetAccess();

        final Web3AuthResponse response = await method();
        BlocProvider.of<AuthCubit>(context).btnLoader(false);

        final prefs = await SharedPreferences.getInstance();
        log('${response}fahad');
        await prefs.setString('privateKey', response.privKey.toString());

        print(response.userInfo!.email);
        print(response.userInfo!.name);

        String key = Constant.webAuthKey;
        final claimSet = JwtClaim(otherClaims: <String, dynamic>{
          "decodePrivateKey": response.privKey.toString()
        }, expiry: DateTime.now().add(const Duration(days: 7)));

        final jwttoken = issueJwtHS256(claimSet, key);
        AuthRepository auth = AuthRepository();
        auth.generateWalllet(context, jwttoken, response.userInfo!.email!);
        // Call onSuccessNavigation if login is successful
      } on UnKnownException {
        log("Unknown exception occurred");
      } catch (e) {
        print(e);
      }
    };
  }       
Future<Web3AuthResponse> withEmailPasswordless(
      GlobalKey<FormState> loginformKey, context, String userEmail) async {
    BlocProvider.of<AuthCubit>(context).btnLoader(true);
    print('press');
    Timer(const Duration(seconds: 2),
        () => BlocProvider.of<AuthCubit>(context).btnLoader(false));
    bool check = await Globals.isInternetConnected();
    if (!check) {
      Globals.showToast(
          'Network Error: There was a problem connecting to our servers. Please check your internet connection and try again.');
      return Future.error("No internet connection");
    }
    if (state.emailController!.text != '' &&
        RegExp(r'^[a-zA-Z0-9]+[a-zA-Z0-9._%+-]*@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$',
                caseSensitive: false
                //r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))+'
                // r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+"
                )
            .hasMatch(state.emailController!.text)) {
      try {
        emit(state.copywith(eemailError: ''));
        print('dksah');
        return await Web3AuthFlutter.login(LoginParams(
          loginProvider: Provider.email_passwordless,
          extraLoginOptions: ExtraLoginOptions(login_hint: userEmail),
        ));
        // IMP END - Login
      } catch (e) {
        print("Error during email/passwordless login: $e");

        // Handle the error as needed
        // You might want to show a user-friendly message or log the error
        return Future.error("Login failed$e");
      }
    } else {
      if (state.emailController!.text.isEmpty &&
          state.emailController != null) {
        BlocProvider.of<AuthCubit>(context)
            .updateEmailError("Please enter your email");
        BlocProvider.of<AuthCubit>(context).updatelogin(false);
      } else if (!RegExp(
              r'^[a-zA-Z0-9]+[a-zA-Z0-9._%+-]*@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$',
              caseSensitive: false)
          .hasMatch(state.emailController!.text)) {
        BlocProvider.of<AuthCubit>(context)
            .updateEmailError("Invalid email address");
        BlocProvider.of<AuthCubit>(context).updatelogin(false);
      }
    }
    return Future.error("Login failed");
    //  return Future.error("Login failed");
  }

after calling this on tap and inserting email the above functions runs for passwordless otp on web3auth

()=>BlocProvider.of<AuthCubit>(
                                                      context)
                                                  .loginF(
                                                  _formKey,
                                                  context,
                                                  () => BlocProvider.of<
                                                          AuthCubit>(context)
                                                      .withEmailPasswordless(
                                                          _formKey,
                                                          context,
                                                          state.emailController!
                                                              .text
                                                              .trim()),
                                                )

some time it is re-produce, the private key is generated and the function login is successful and it allows to navigate based on our login but something after private key is generate the error wont be their but it will stop the navigation after success and will need to allow login again.

@shahbaz

Hey, can you please join our office hours? We can debug it on the call, if it works for you. Also, is it possible to show a video recording of the issue?