PhoneAuthProvider.OnVerificationStateChangedCallbacks没有被触发。

huangapple go评论66阅读模式
英文:

PhoneAuthProvider.OnVerificationStateChangedCallbacks not getting fired

问题

我使用Firebase的手机号验证功能构建了一个应用程序的身份验证功能。我进行了多台测试设备的测试,一切正常。

然而,我清除了我的测试手机,重新启动并决定再次测试同一个应用程序。这次,我注意到OnVerificationStateChangedCallbacks中的任何一个方法都没有被触发

这尤其令人惊讶,因为我根本没有编辑过代码库。我在每个三个方法的开头处放置了日志,但没有一个被调用。从本质上讲,OnVerificationStateChangedCallbacks没有起作用。

以下是我初始化OnVerificationStateChangedCallbacks的代码片段:

onVerificationStateChangedCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
    @Override
    public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
        Log.d(TAG, "verification completed " + phoneAuthCredential.toString());
        // 一些操作
    }

    @Override
    public void onVerificationFailed(@NonNull FirebaseException e) {
        Log.d(TAG, "verification failed " + e.getMessage());
        // 一些操作
    }

    @Override
    public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
        Log.d(TAG, "Code sent " + s);
        // 一些操作
    }
};

我的日志没有捕获到任何信息。并且回调中的任何方法都没有被执行。

额外的步骤已采取:

  • 我检查了Firebase仪表板,以确保我没有超过免费配额。
  • 我确认电话号码仍然设置为登录方法之一。

问题可能是什么?

英文:

I built the authentication feature of an app using Firebase's phone number verification. I tested and everything worked fine for multiple test devices.

However, I wiped my test phone, rebooted and decided to test the same app again. This time, I noticed that NONE of the methods in OnVerificationStateChangedCallbacks were being fired.

This was particularly surprising because I had not edited the codebase at all. I placed logs at the start of each of the three methods and none of them got called. In essence, OnVerificationStateChangedCallbacks is not working.

Here's a snippet of my OnVerificationStateChangedCallbacks initialization:

onVerificationStateChangedCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
        @Override
        public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
            Log.d(TAG, "verification completed "+ phoneAuthCredential.toString());
            // some stuff
        }

        @Override
        public void onVerificationFailed(@NonNull FirebaseException e) {
            Log.d(TAG, "verification failed "+ e.getMessage());
            // some stuff
        }

        @Override
        public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {

            Log.d(TAG, "Code sent "+ s);
            // some stuff
        }
    };

<br />
My logs are not picking up anything. Also, none of the methods in the callback are being executed.

<br />

Extra steps taken:

  • I checked the Firebase dashboard to make sure I had not exceeded the free quota.
  • I confirmed that phone number was still set as one of the sign-in methods.

<br />
What could be the problem?

答案1

得分: 1

整个问题中关键的句子是:

> 然而,我清除了我的测试手机,重新启动并决定再次测试相同的应用。

Firebase手机认证的官方文档 指出,在 verifyPhoneNumber 函数能够工作之前,设备必须安装并更新了Google Play服务。由于Google Play服务要么缺失要么过时,导致没有任何回调被触发。

另一种可能解决这个问题的方法是使用定时请求或者尝试捕获。

注意: 我觉得很奇怪的是,由于这个原因没有调用 OnVerificationFailed()。由于大多数开发者通常依赖这三个回调方法来保持流程的连续性,这可能算作一个问题。

英文:

The key sentence in the entire question is:

> However, I wiped my test phone, rebooted and decided to test the same app again.

The official documentation for Firebase phone-auth states that Google Play services of a device MUST be installed and up-to-date before the verifyPhoneNumber function can work. None of the callbacks were being fired because Google Play Services was either missing or outdated.

Another potential way to resolve this issue is to use timed requests or try-and-catch.

NB: I think it's quite odd that OnVerificationFailed() was not called due to this. Since most developers typically rely on these three callback methods for flow continuity, this might count as an issue.

huangapple
  • 本文由 发表于 2020年3月16日 10:21:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/60699605.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定