[Archive] App crash on login

:classical_building: Archived Content from Web3Auth Community

This topic was originally posted by danil.makarenko on 7/30/2024.
This content has been migrated from our previous community forum to preserve valuable discussions.


  • SDK Version: 8.0.1
  • Platform: Android

Some of our users are facing app crashes when logging in.
I am not sure whether it’s related to the device or not, but most of the users have no problems

Here is the email of one of the affected users.
tiagocappelle@gmail.com

The crash comes from PnP SDK

          Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String j7.a.getString(java.lang.String, java.lang.String)' on a null object reference
       at com.web3auth.session_manager_android.keystore.KeyStoreManager.getPreferencesData(KeyStoreManager.java:134)
       at com.web3auth.session_manager_android.SessionManager.authorizeSession(SessionManager.kt:138)
       at com.web3auth.core.Web3Auth.authorizeSession(Web3Auth.kt:335)
       at com.web3auth.core.Web3Auth.initialize(Web3Auth.kt:170)
       at com.app.renegade.ui.home.HomeBaseActivity.login(HomeBaseActivity.kt:258)
       at com.app.renegade.ui.vault.custom_web3auth.CustomWalletRouteKt$CustomWalletScreen$2.invokeSuspend(CustomWalletRoute.kt:114)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
       at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch(AndroidUiDispatcher.android.kt:81)
       at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch(AndroidUiDispatcher.android.kt:41)
       at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.run(AndroidUiDispatcher.android.kt:57)
       at android.os.Handler.handleCallback(Handler.java:958)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:230)
       at android.os.Looper.loop(Looper.java:319)
       at android.app.ActivityThread.main(ActivityThread.java:8919)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)

Looks like the storage has been deleted, and we can’t find any active session. Please tell them to logout if they can and re-login if they can. The other option would be to deleted the app, and install again but please make sure user has enabled the MFA option, otherwise they will lose access to their account.

Also, can you share your initalize code?

private fun initWeb3Auth() {
        web3Auth = Web3Auth(
            Web3AuthOptions(
                context = this@HomeBaseActivity,
                clientId = BuildConfig.WEB3AUTH_CLIENT_ID,
                network = if (BuildConfig.FLAVOR == "dev") Network.SAPPHIRE_DEVNET else Network.SAPPHIRE_MAINNET,
                redirectUrl = Uri.parse("${BuildConfig.APPLICATION_ID}://auth"), // your app's redirect URL,
                loginConfig = hashMapOf(
                    "jwt" to LoginConfigItem(
                        verifier = BuildConfig.WALLET_VERIFIER_NAME,
                        typeOfLogin = TypeOfLogin.JWT,
                        clientId = BuildConfig.WEB3AUTH_CLIENT_ID
                    )
                )
            )
        )
    }

override fun login(
        token: String,
        onSuccess: (response: Web3AuthResponse) -> Unit,
        onError: (throwable: Throwable) -> Unit
    ) {
        val sessionResponse: CompletableFuture<Void> = web3Auth.initialize()
        sessionResponse.whenComplete { _, error ->
            if (error == null) {
                try {
                    // User is already logged in
                    web3Auth.getWeb3AuthResponse()?.let { onSuccess(it) }
                } catch (e: Throwable) {
                    // during the session check, the user info will not be available, so we need to login
                    signIn(
                        token = token,
                        onLoginSuccess = onSuccess,
                        onLoginFailed = onError
                    )
                }
            } else {
                signIn(
                    token = token,
                    onLoginSuccess = onSuccess,
                    onLoginFailed = onError
                )
            }
        }
    }

private fun signIn(
        token: String,
        onLoginSuccess: (Web3AuthResponse) -> Unit,
        onLoginFailed: (throwable: Throwable) -> Unit,
    ) {
        val loginCompletableFuture = web3Auth.login(
            LoginParams(
                Provider.JWT,
                extraLoginOptions = ExtraLoginOptions(id_token = token),
                mfaLevel = MFALevel.MANDATORY
            )
        )

        loginCompletableFuture.whenComplete { loginResponse, error ->
            if (error == null) {
                onLoginSuccess(loginResponse)
            } else {
                Timber.e(error)
                onLoginFailed(error)
            }
        }
    }

I don’t see any issue in the code that could trigger that, can you relay the above steps to user and ask if it works? If it doesn’t work, please get the user’s device details to debug the issue.