Search code examples
androidtwitter-digits

Digits android authcallback not called on success/failure otp verification


I am creating a digitsauthconfig like this:

private DigitsAuthConfig createDigitsAuthConfig() {
    return new DigitsAuthConfig.Builder()
            .withAuthCallBack(createAuthCallback())
            .withPhoneNumber("+91")
            .withThemeResId(R.style.CustomDigitsTheme)
            .build();
}

Where authcallback is returned by:

private AuthCallback createAuthCallback() {
    return new AuthCallback() {
        @Override
        public void success(DigitsSession session, String phoneNumber) {
            doIfSuccessfulOtpVerification();
        }

        @Override
        public void failure(DigitsException exception) {
            doIfNotSuccessfulOtpVerification();
        }
    };
}

I initiate the process using a button with event listener:

digitsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Digits.authenticate(createDigitsAuthConfig());
        }
    });

The problem is, once my phone number is verified, it goes back to the activity where the button is displayed and does nothing. Technically, the authcallback is never called, doesn't matter successful or not. But if I click the button again, the authcallback is called without repeating the verification step. So right now I am required to click the button twice. What is the way around it?


Solution

  • Finally i got solution for that issue, May it will help you too also.

    You need to remove the ActiveSession, before calling the setCallback(authCallback) like mentioned as below.It will remove the existing session(if you already entered your phone number and got an OTP) from digits. This session will will not allows you to make another session to generate an OTP. So, we have to remove it. And it will work if there is no any previous sessions.

        DigitsAuthButton digitsButton = (DigitsAuthButton) findViewById(R.id.auth_button);
        Digits.getSessionManager().clearActiveSession();
        digitsButton.setCallback(((WyzConnectApp) getApplication()).getAuthCallback());