Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Login with LoginType.PHONE only completes the promise for the first time #657

Closed
jnorkus opened this issue Mar 27, 2018 · 6 comments
Closed
Assignees
Milestone

Comments

@jnorkus
Copy link
Collaborator

jnorkus commented Mar 27, 2018

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');
    });
}
@jnorkus
Copy link
Collaborator Author

jnorkus commented Mar 27, 2018

Could be related
#462

@jnorkus jnorkus changed the title Login promise not rejected on second failure with LoginType.PHONE Login with LoginType.PHONE only completes the promise for the first time Mar 28, 2018
@EddyVerbruggen EddyVerbruggen added this to the 5.2.0 milestone Mar 30, 2018
@EddyVerbruggen EddyVerbruggen self-assigned this Mar 30, 2018
@EddyVerbruggen
Copy link
Owner

EddyVerbruggen commented Mar 30, 2018

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

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

@jnorkus
Copy link
Collaborator Author

jnorkus commented Apr 3, 2018

@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.

@jnorkus
Copy link
Collaborator Author

jnorkus commented Apr 17, 2018

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

@EddyVerbruggen
Copy link
Owner

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

@jnorkus
Copy link
Collaborator Author

jnorkus commented Apr 17, 2018

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants