arnesson / cordova-plugin-firebase

Cordova plugin for Google Firebase
http://arnesson.github.io/cordova-plugin-firebase
MIT License
1.01k stars 1.56k forks source link

Verification id is not getting in Android #983

Open saravananmani1988 opened 5 years ago

saravananmani1988 commented 5 years ago

Describe the bug I'm using Ionic4 with this Native Firebase plugin by following https://beta.ionicframework.com/docs/native/firebase

When i call verifyPhoneNumber im getting the following response from the promise return.

{verified: false, instantVerification: true}

I dont see the code in the response. as per the API docs i should get code form the response if the instentverification is true.

here is my code in TypeScript. <<<<<<>>>>>>>>>>>>>>

import {Component, OnInit} from '@angular/core'; import {AlertController, NavController, ToastController, Platform } from '@ionic/angular'; import * as firebase from 'firebase'; import {AngularFireAuth} from '@angular/fire/auth'; import { Firebase } from '@ionic-native/firebase/ngx';

@Component({ selector: 'app-home', templateUrl: 'home.page.html', styleUrls: ['home.page.scss'], })

export class HomePage implements OnInit {

phoneNumber: number;
code: string;
verificationId: string;

constructor(public afAuth: AngularFireAuth,
            public platform: Platform,
            private firebaseNative: Firebase) {

    afAuth.authState.subscribe(user => {
        if (user) {
            console.log('User already logged in');
            console.log(user);
        } else {
          console.log('User not logged in');
        }

    });

}

ngOnInit() {
    this.initializeApp();
}

initializeApp() {
    this.platform.ready().then(() => {
        console.log('Platform is ready');
    });
}

doLogin() {
    console.log('Login initiated');
    console.log('Phone no is: ' + this.phoneNumber);
    this.firebaseNative.verifyPhoneNumber('+91' + this.phoneNumber, 5)
        .then(res => {
        console.log(res);

        this.verificationId = res;
        })
        .catch(error => {
            console.log(error);
        });

}

doVerify() {

    const signInCredential = firebase.auth.PhoneAuthProvider.credential(this.verificationId, this.code);

    this.afAuth.auth.signInAndRetrieveDataWithCredential(signInCredential)
        .then(res => {
            console.log(res);
        })
        .catch(error => {
            console.log(error);
        });
}

}

<<<<>>>>>>>>>>>>>>

To Reproduce Steps to reproduce the behavior: Create a new Ionic 4 blank project and all the plugin as described in the docs and call the method from a html page.

Expected behavior As per docs it should give the code as output if the verification is true.

Screenshots image

Console Logs

Plugin Version "cordova-plugin-firebase@2.0.5",

Smartphone (please complete the following information):

uokivan commented 5 years ago

How about in iOS ? can u getting it on iphone?

saravananmani1988 commented 5 years ago

@uokivan sorry i don't have an IOS device to test.

elikr commented 5 years ago

I'm experiencing the same issue. instantVerification is true, and the verified is false, and nothing else is returned from the plugin. No verificationId, no code. This means I can't really log into AngularFire with Android phones that have auto-verification on at the moment.

Not really an Android developer, but I've dug around the code, and added a log statement in FirebasePlugin.java:

Field[] fields = credential.getClass().getDeclaredFields();
for (Field field : fields) {
    Class type = field.getType();
    if(type == String.class){
        String value = getPrivateField(credential, field);
        Log.d(TAG, "field value: " + value);

        if(value == null) continue;
        if(value.length() > 100) verificationId = value;
        else if(value.length() >= 4 && value.length() <= 6) code = value;
    }
}

The values I see in logcat are

field value: null
field value: null
field value: (my full phone number)
field value: null

So it seems that the plugin relies on certain private fields of PhoneAuthCredential that are not actually sent by Firebase anymore, during Android's auto-verify onVerificationCompleted.

Plugin version: 2.0.5. Using both @ionic-native/firebase@4.20.0 and directly via window.FirebasePlugin. Device: Huawei Mate 10 Pro, EMUI 9.0.0.179, Android 9