Digits android authcallback not called on success/failure otp verification

814 views Asked by At

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?

3

There are 3 answers

0
Narendra Baratam On BEST ANSWER

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());
0
Dr. Abhishek On

I know its late but may be helpful for a beginner.To verify that the session is already active, please put this code in your onCreate of that activity in which Digits phone number verification button is initialised:

 TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
            Fabric.with(this, new TwitterCore(authConfig), new Digits.Builder().build());
    if (Digits.getActiveSession() != null) {
                Intent ss = new Intent(CurrentActivity.this, SecondActivity.class);
                startActivity(ss);
                finish();
            }
0
Zain Ali On

Digits changed the way it reference the AuthCallback passed in the Digits#authenticate call.
Now Digits holds a weak reference (to avoid a memory leak), unless you hold a strong reference, that AuthCallback will be garbage collected and the result of the flow will be never propagated.
You need to define the AuthCallback in the Application context and then use this callback in your activity and it should work.
Please check the documentation on how to do this