Cordova-plugin-firebasex: No credential.code received although credential.instantVerification is true

Created on 10 Oct 2019  路  11Comments  路  Source: dpa99c/cordova-plugin-firebasex

Bug report

Current behavior:
Calling verifyPhoneNumber on android triggers instantverification however no code is sent in the credential object. I do get key verified: false though which means no verificationId and no code.

Edit: The PhoneAuth user account is being created on firebase console. So, there's no doubt that verification was succesful.

Expected behavior:

Expected behavior is to get code in the credential object when credential.instantVerification is true

Environment information

  • Cordova CLI version
  • Cordova platform version

    • android 8.1.0

  • Plugins & versions installed in project (including this plugin)
    cordova-plugin-androidx 1.0.2 "cordova-plugin-androidx"
    cordova-plugin-androidx-adapter 1.1.0 "cordova-plugin-androidx-adapter"
    cordova-plugin-device 1.1.7 "Device"
    cordova-plugin-firebase-analytics 3.0.0 "FirebaseAnalyticsPlugin"
    cordova-plugin-firebase-messaging 3.0.0 "FirebaseMessagingPlugin"
    cordova-plugin-firebasex 6.1.0 "Google Firebase Plugin"
    cordova-plugin-google-analytics 1.8.6 "Google Universal Analytics Plugin"
    cordova-plugin-inappbrowser 3.0.0 "InAppBrowser"
    cordova-plugin-keyboard 1.2.0 "Keyboard"
    cordova-plugin-safariviewcontroller 1.6.0 "SafariViewController"
    cordova-plugin-screen-orientation 3.0.1 "Screen Orientation"
    cordova-plugin-splashscreen 5.0.2 "Splashscreen"
    cordova-plugin-statusbar 2.4.2 "StatusBar"
    cordova-plugin-whitelist 1.3.3 "Whitelist"
    cordova-plugin-wkwebview-engine 1.1.4 "Cordova WKWebView Engine"
    cordova-support-android-plugin 1.0.1 "cordova-support-android-plugin"
    cordova-support-google-services 1.3.1 "cordova-support-google-services"
    es6-promise-plugin 4.2.2 "Promise"
  • Dev machine OS and version, e.g.

    • Windows 10



      • Version 1903 (OS Build 18362.388)



_Runtime issue_

  • Device details

    • Huawei Y9 (2018)

  • OS details

    • Android 9.0

_Android build issue:_

  • Node JS version

    • 10.16.2

Related code:

window.FirebasePlugin.verifyPhoneNumber(phoneNumber, 0, (credential) => {
          if(typeof credential === 'object') {
            if(credential.instantVerification) {
              console.log('instant verification')
              console.log('credential.code', credential.code)
            } else {
              console.log('not instant verification')
            }
          }
        }, (error) => {
          console.log('error', error)
        })

Console output


console output


instant verification
credential.code undefined



android bug legacy runtime issue

All 11 comments

I think this line here is not returning correct field value or there might have been changes to PhoneAuthCredential on firebase api

There had been discussion about it on original repo about this. https://github.com/arnesson/cordova-plugin-firebase/pull/861

verifyPhoneNumber() has been reworked in v7.0.0 of this plugin which should resolve your issue.
Please retest using the example project.
You can use the newly added fakeVerificationCode option to test instant verification on Android which uses the officially sanctioned method - see the updated documentation for more details.

If you still encounter issues, please respond here and I will reopen the issue to investigate.

hey @dpa99c,

When I'm using the devices phone number I received instantVerification = true, without the verificationId or code. The expected output here would be with the verificationId and Code

When I'm using a phone number of a different device, I receive instantVerification = true along with the verificationId and a null code. The expected outcome here would be only the verificationId.

I've not developed any cordova plugins before but I'm going to see if I can create an PR for this.

@MattGould1 As you can see in the source code, instantVerification: true is only ever set in the onVerificationCompleted() callback which is the instant verification callback.
In my testing using the example project, this behaved as expected and when onVerificationCompleted() was called, the verificationId and code were resolved.
Could you try to reproduce the issue using the example project?

hey @dpa99c sorry, I didn't mention that was with https://github.com/dpa99c/cordova-plugin-firebasex-test

I get the same results within my actual project as well.

Here's a look at what onVerificationCompleted is receiving.

credential = {PhoneAuthCredential@8547} 
  zza = null
  zzb = null
  zzc = true
  zzd = "PHONE_NUMBER"
  zze = true
  zzf = null
  zzg = null

This is what is received when using a phone number where instant verification shouldn't be possible

credential = {PhoneAuthCredential@8575} 
 zza = "AM5PThDaZfNM63JRgqowSNAjLhHTZq8ceLYKQD8j9z1kcbcWzv9kQiFziy81ghjOmEFo1S88ml-4Rdfrw3LNjzcPoJ30I270ejNROXKs21YkbTjkxmt6oXULDw283OnLJGgCE5c3pvr1w3XKFfYZKR9DzlqVSPpRl2IzVjkceeDpR3VsFvtDkv3W2RNMPraK2wmZC1HeySoag-ixq7J4I6j1fBAFOO_feL2e5PhnGjSbsRkS8s0"
 zzb = "null"
 zzc = false
 zzd = null
 zze = true
 zzf = null
 zzg = null

I can still confirm that the credential.code and credential.verificationId are not resolved although onVerificationCompleted gets called.

As I mentioned in earlier comment, there has been some changes to firebase API such that the private fields like code and verificationId of PhoneAuthCredential are hard to retrieve. I tried playing with it but couldn't get those fields.
Here is the source code which might need modifications: https://github.com/dpa99c/cordova-plugin-firebasex/blob/master/src/android/FirebasePlugin.java#L818:L827

Mind that I tried trigerring instant verification in a real android device instead of setting up test phone number in firebase console.

quick update, if this helps I'm able to sign in with the credential using FirebaseAuth.getInstance().signInWithCredential(credential)

but the credential is still missing the verificationId and code.

hey @dpa99c,

The only way to get this functionality to work for me was by implementing the native signInWithCredential method. After that, I implemented a native function to get the users idToken and then used the idToken to verify with my server.

I am also encountering the same issue, I'm using plugin version v7.0.1
The only field I get at the credential object is instantVerification with true value, while credential.code and credential.verificationId field still not found
image

The internal reflection approach inherited from cordova-plugin-firebase is the issue here.
There is no reason to extract the credentials from the native Java credential object and return it to the JS layer.
So I will rework the implementation of verifyPhoneNumber() as part of #208 to retain the credential in the native layer on both Android & iOS, which is a more stable approach.
However, be warned this will make breaking changes to the plugin API.

Was this page helpful?
0 / 5 - 0 ratings