Nativescript-plugin-firebase: Login with LoginType.PHONE only completes the promise for the first time

Created on 27 Mar 2018  路  6Comments  路  Source: EddyVerbruggen/nativescript-plugin-firebase

Platform: Android

firebase.login({
    type: firebase.LoginType.PHONE,
    phoneOptions: {
        phoneNumber: '+37011'
    }
}).catch(error => {
    console.log(error);
});

First time this works as expected, failing and rejecting the promise, console.log outputing the error message. Second time the promise is not rejected.

I've debugged this all the way to firebase.android.js, this line:
var OnVerificationStateChangedCallbacks = com.google.firebase.auth.PhoneAuthProvider.OnVerificationStateChangedCallbacks.extend({

The callbacks work as expected and actually call reject(errorMessage); but for some reason after the first failure any subsequent calls will not reject the promise.

I would be willing to help in fixing this (if indeed it is a bug) but I'm pretty new to Nativescript and mobile development and not sure what the extend() call is or how to debug native code. It seems to be the root of the problem. I have tried calling the callback directly on the object returned by extend and could reproduce.

UPDATE:
Isolated reproduction. Please note that it doesn't matter if it's a resolve or reject - it only works the first time.

reproduce().catch(console.log);

function reproduce() {
    return new Promise((resolve, reject) => {
        var OnVerificationStateChangedCallbacks = com.google.firebase.auth.PhoneAuthProvider.OnVerificationStateChangedCallbacks.extend({
            onVerificationCompleted: (phoneAuthCredential) => {
                resolve(phoneAuthCredential);
            },
            onVerificationFailed: function (firebaseException) {
                reject(firebaseException);
            }
        });

        const cbs = new OnVerificationStateChangedCallbacks();
        cbs.onVerificationFailed('something went wrong');
    });
}
Android bug

All 6 comments

Indeed, looks like #462 is related. This will be fixed with 5.2.0.

Btw, perfect bug report, thanks for all your efforts!

@EddyVerbruggen
The fix is not complete - this is not used in the onComplete callback. This results in promise not being resolved after first reject. Strangely though, the next time resolve is called it works.

@EddyVerbruggen do you want me to create another pull request to fix it?

If you can, please do. I could also grant you commit access if you like.

I guess that would make it easier for me so sure why not!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

b02505048 picture b02505048  路  3Comments

romandragan picture romandragan  路  3Comments

WaseemAhmadZ picture WaseemAhmadZ  路  3Comments

NickIliev picture NickIliev  路  3Comments

phatakrajan picture phatakrajan  路  4Comments